obnizのフォーラムは新しいシステムに移行しております。

新しいフォーラムはこちらになります

obnizをcentralとしてperipheralにconnectできない



  • peripheral.connect()して30秒程で、peripheral.onerrorがerror_code=255で呼び出されます。
    その直後にperipheral.ondisconnectが呼び出され、connectできません。(peripheral.onconnectが呼ばれません)

    下記のdebug printから原因等が判るでしょうか?

    [Log] Obniz: send: [{"ble":{"scan":{"duration":30}}}] (obniz.js, line 7931)
    [Log] 2.543 scan start! (obniz.js, line 22)
    [Log] Obniz: send via local (obniz.js, line 7931)
    [Log] Obniz: 11,4,4,0,0,0,30 (obniz.js, line 7931)
    [Log] Obniz: recvd via local (obniz.js, line 7931)
    [Log] Obniz: {"ble":{"scan_result":{"address":"d8461abc62e0","device_type":"ble","address_type":"random","ble_event_type":"connectable_advertisemnt","rssi":-56,"adv_data":[18,9,77,69,83,72,45,49,48,48,66,85,49,48,48,52,54,54,53,2,1,6],"flag":6,"scan_resp":[17,7,158,159,236,34,78,83,70,183,64,77,169,87,1,0,201,114]}}} (obniz.js, line 7931)
    [Log] Obniz: send: [{"ble":{"scan":null}}] (obniz.js, line 7931)
    [Log] 6.777 onfind: d8461abc62e0 (obniz.js, line 22)
    [Log] BleRemotePeripheral {Obniz: Obniz, address: "d8461abc62e0", connected: false, device_type: "ble", address_type: "random", …} (mesh_button.html, line 41)
    [Log] Obniz: send: [{"ble":{"connect":{"address":"d8461abc62e0"}}}] (obniz.js, line 7931)
    [Log] Obniz: send via local (obniz.js, line 7931)
    [Log] Obniz: 11,5,0,11,7,7,224,98,188,26,70,216,0 (obniz.js, line 7931)
    [Log] Obniz: {"ble":{"error":{"error_code":255,"address":"d8461abc62e0","service_uuid":null,"characteristic_uuid":null,"descriptor_uuid":null,"message":"error on connecting device"}}} (obniz.js, line 7931)
    [Log] 36.976 error : error on connecting device (obniz.js, line 22)
    [Log] {error_code: 255, address: "d8461abc62e0", service_uuid: null, characteristic_uuid: null, descriptor_uuid: null, …} (mesh_button.html, line 52)
    [Log] Obniz: {"ble":{"status_update":{"address":"d8461abc62e0","status":"disconnected"}}} (obniz.js, line 7931)
    [Log] 36.978 disconnected (obniz.js, line 22)
    

    ソース抜粋

    obniz.onconnect = async function () {
    
      obniz.ble.scan.onfind = async function(peripheral) {
        obniz.ble.scan.end();
        console.log("onfind: " + peripheral.address);
        console.log(peripheral)
        let localName = peripheral.localName;
        if (localName.indexOf("MES") == 0) {
          peripheral.onconnect = function() {
            console.log("connected to " + localName);
          }
          peripheral.ondisconnect = function() {
            console.log("disconnected");
          }
          peripheral.onerror = function(err) {
            console.log("error : " + err.message);
            console.log(err);
          }
          peripheral.connect();
        }
      }
    
      obniz.ble.scan.onfinish = function(peripheral) {
          console.log("scan end!")
      }
    
      obniz.ble.scan.start();
    }
    

    ちなみに、このperipheralデバイスですが、iOSアプリからは普通にconnectできます。

    よろしくお願いします。



  • 追加情報です。

    同じソースコードで別なperipheralデバイスで試したところ、connect()がきっかけでなぜかwifiの再接続が発生しました。(当然peripheralデバイスとはconnectできません)
    ログ(debug print)を以下に示します。

    [Log] Obniz: send: [{"ble":{"scan":{"duration":30}}}] (obniz.js, line 7931)
    [Log] 4.010 scan start! (obniz.js, line 22)
    [Log] Obniz: send via local (obniz.js, line 7931)
    [Log] Obniz: 11,4,4,0,0,0,30 (obniz.js, line 7931)
    [Log] Obniz: recvd via local (obniz.js, line 7931)
    [Log] Obniz: {"ble":{"scan_result":{"address":"c93e073987ed","device_type":"ble","address_type":"random","ble_event_type":"connectable_advertisemnt","rssi":-45,"adv_data":[18,9,77,69,83,72,45,49,48,48,65,67,49,48,48,52,56,54,53,2,1,6],"flag":6,"scan_resp":[17,7,158,159,236,34,78,83,70,183,64,77,169,87,1,0,201,114]}}} (obniz.js, line 7931)
    [Log] Obniz: send: [{"ble":{"scan":null}}] (obniz.js, line 7931)
    [Log] 9.271 onfind: c93e073987ed (obniz.js, line 22)
    [Log] BleRemotePeripheral {Obniz: Obniz, address: "c93e073987ed", connected: false, device_type: "ble", address_type: "random", …} (private_mesh_button.html, line 41)
    [Log] Obniz: send: [{"ble":{"connect":{"address":"c93e073987ed"}}}] (obniz.js, line 7931)
    [Log] Obniz: send via local (obniz.js, line 7931)
    [Log] Obniz: 11,5,0,11,7,7,237,135,57,7,62,201,0 (obniz.js, line 7931)
    [Log] Obniz: closed (obniz.js, line 7931)
    [Log] Obniz: components state resets (obniz.js, line 7931)
    [Log] Obniz: connecting to wss://obniz.io/obniz/9999-3725/ws/1?obnizjs=1.9.5&accept_binary=true (obniz.js, line 7931)
    [Log] Obniz: ws connected (obniz.js, line 7931)
    [Log] Obniz: {"ws":{"redirect":"wss://1.ws.obniz.io"}} (obniz.js, line 7931)
    [Log] Obniz: WS connection changed to wss://1.ws.obniz.io (obniz.js, line 7931)
    [Log] Obniz: connecting to wss://1.ws.obniz.io/obniz/9999-3725/ws/1?obnizjs=1.9.5&accept_binary=true (obniz.js, line 7931)
    [Log] Obniz: ws connected (obniz.js, line 7931)
    [Log] Obniz: {"ws":{"ready":true,"obniz":{"firmware":"1.0.8"},"local_connect":{"ip":"192.168.1.32"}}} (obniz.js, line 7931)
    [Log] Obniz: send: [{"ws":{"reset_obniz_on_ws_disconnection":true}}] (obniz.js, line 7931)
    [Log] Obniz: local connect to ws://192.168.1.32 (obniz.js, line 7931)
    [Log] Obniz: connected to ws://192.168.1.32 (obniz.js, line 7931)
    

    よろしくお願いします。



  • @nak435 ご連絡ありがとうございます。
    こちら確認しておりますので、もう少しお待ち下さい。



  • @nak435 さん

    こちら確認しておりますが,手持ちのデバイスで現象が再現できておらず,まだ原因追求ができていない状態です.

    もしつなぐデバイスが既成品でしたら,その商品を教えていただけないでしょうか.

    また,obnizjsの最新バージョン(1.10.0)にてデバッグ情報を強化するコマンドdebugprintBinaryを追加しました.
    こちらをつけて実行したログを見せていただければ,もう少し詳細がわかるかもしれませんので,試してみていただけないでしょうか.

    <script src="https://unpkg.com/obniz@1.10.0/obniz.js" crossorigin="anonymous"></script>
    
    <script>
    var obniz = new Obniz("XXXXXXXX");
    obniz.debugprint = true;
    obniz.debugprintBinary = true;
    
    ...
    
    </script>
    
    


  • kido@obnizさん

    obniz.debugprintBinary = true;を追加したログは以下の通りです。

    エラーになるパターン

    [Log] Obniz: send: [{"ble":{"scan":{"duration":30}}}] (obniz.js, line 7929)
    [Log] Obniz: binalized: 11,4,4,0,0,0,30 (obniz.js, line 7929)
    [Log] 83.447 scan start! (obniz.js, line 22)
    [Log] Obniz: send via local (obniz.js, line 7929)
    [Log] Obniz: recvd via local (obniz.js, line 7929)
    [Log] Obniz: 11,6,64,86,0,208,56,242,246,241,123,2,1,0,255,255,255,201,18,9,77,69,83,72,45,49,48,48,76,69,49,48,48,52,52,48,48,2,1,6,17,7,158,159,236,34,78,83,70,183,64,77,169,87,1,0,201,114,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,1,22,18 (obniz.js, line 7929)
    [Log] Obniz: {"ble":{"scan_result":{"address":"7bf1f6f238d0","device_type":"ble","address_type":"random","ble_event_type":"connectable_advertisemnt","rssi":-55,"adv_data":[18,9,77,69,83,72,45,49,48,48,76,69,49,48,48,52,52,48,48,2,1,6],"flag":6,"scan_resp":[17,7,158,159,236,34,78,83,70,183,64,77,169,87,1,0,201,114]}}} (obniz.js, line 7929)
    [Log] Obniz: send: [{"ble":{"scan":null}}] (obniz.js, line 7929)
    [Log] Obniz: binalized: 11,5,0 (obniz.js, line 7929)
    [Log] 83.614 onfind: 7bf1f6f238d0 (obniz.js, line 22)
    [Log] BleRemotePeripheral {Obniz: Obniz, address: "7bf1f6f238d0", connected: false, device_type: "ble", address_type: "random", …} (private_mesh_button.html, line 43)
    [Log] 12 9 4d 45 53 48 2d 31 30 30 4c 45 31 30 30 34 34 30 30 2 1 6 (private_mesh_button.html, line 44)
    [Log] Obniz: send: [{"ble":{"connect":{"address":"7bf1f6f238d0"}}}] (obniz.js, line 7929)
    [Log] Obniz: binalized: 11,7,7,208,56,242,246,241,123,0 (obniz.js, line 7929)
    [Log] Obniz: send via local (obniz.js, line 7929)
    [Log] Obniz: 11,255,64,64,133,255,7,208,56,242,246,241,123,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 (obniz.js, line 7929)
    [Log] Obniz: {"ble":{"error":{"module_error_code":133,"error_code":255,"function_code":7,"address":"7bf1f6f238d0","service_uuid":null,"characteristic_uuid":null,"descriptor_uuid":null,"message":"error on connecting device"}}} (obniz.js, line 7929)
    [Log] 113.773 error : error on connecting device (obniz.js, line 22)
    [Log] {module_error_code: 133, error_code: 255, function_code: 7, address: "7bf1f6f238d0", service_uuid: null, …} (private_mesh_button.html, line 55)
    [Log] Obniz: 11,7,7,208,56,242,246,241,123,1 (obniz.js, line 7929)
    [Log] Obniz: {"ble":{"status_update":{"address":"7bf1f6f238d0","status":"disconnected"}}} (obniz.js, line 7929)
    [Log] 113.775 disconnected (obniz.js, line 22)
    

    obniz本体がリセット(?)するパターン

    [Log] Obniz: send: [{"ble":{"scan":{"duration":30}}}] (obniz.js, line 7929)
    [Log] Obniz: binalized: 11,4,4,0,0,0,30 (obniz.js, line 7929)
    [Log] 226.476 scan start! (obniz.js, line 22)
    [Log] Obniz: send via local (obniz.js, line 7929)
    [Log] Obniz: recvd via local (obniz.js, line 7929)
    [Log] Obniz: 11,6,64,86,0,224,98,188,26,70,216,2,1,0,255,255,255,182,18,9,77,69,83,72,45,49,48,48,66,85,49,48,48,52,54,54,53,2,1,6,17,7,158,159,236,34,78,83,70,183,64,77,169,87,1,0,201,114,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,1,22,18 (obniz.js, line 7929)
    [Log] Obniz: {"ble":{"scan_result":{"address":"d8461abc62e0","device_type":"ble","address_type":"random","ble_event_type":"connectable_advertisemnt","rssi":-74,"adv_data":[18,9,77,69,83,72,45,49,48,48,66,85,49,48,48,52,54,54,53,2,1,6],"flag":6,"scan_resp":[17,7,158,159,236,34,78,83,70,183,64,77,169,87,1,0,201,114]}}} (obniz.js, line 7929)
    [Log] Obniz: send: [{"ble":{"scan":null}}] (obniz.js, line 7929)
    [Log] Obniz: binalized: 11,5,0 (obniz.js, line 7929)
    [Log] 226.616 onfind: d8461abc62e0 (obniz.js, line 22)
    [Log] BleRemotePeripheral {Obniz: Obniz, address: "d8461abc62e0", connected: false, device_type: "ble", address_type: "random", …} (private_mesh_button.html, line 43)
    [Log] 12 9 4d 45 53 48 2d 31 30 30 42 55 31 30 30 34 36 36 35 2 1 6 (private_mesh_button.html, line 44)
    [Log] Obniz: send: [{"ble":{"connect":{"address":"d8461abc62e0"}}}] (obniz.js, line 7929)
    [Log] Obniz: binalized: 11,7,7,224,98,188,26,70,216,0 (obniz.js, line 7929)
    [Log] Obniz: send via local (obniz.js, line 7929)
    [Log] Obniz: closed (obniz.js, line 7929)
    [Log] Obniz: components state resets (obniz.js, line 7929)
    [Log] Obniz: connecting to wss://obniz.io/obniz/9999-3725/ws/1?obnizjs=1.10.0&accept_binary=true (obniz.js, line 7929)
    [Log] Obniz: ws connected (obniz.js, line 7929)
    [Log] Obniz: {"ws":{"redirect":"wss://1.ws.obniz.io"}} (obniz.js, line 7929)
    [Log] Obniz: WS connection changed to wss://1.ws.obniz.io (obniz.js, line 7929)
    [Log] Obniz: connecting to wss://1.ws.obniz.io/obniz/9999-3725/ws/1?obnizjs=1.10.0&accept_binary=true (obniz.js, line 7929)
    [Log] Obniz: ws connected (obniz.js, line 7929)
    [Log] Obniz: {"ws":{"ready":true,"obniz":{"firmware":"1.0.8"},"local_connect":{"ip":"192.168.1.32"}}} (obniz.js, line 7929)
    [Log] Obniz: send: [{"ws":{"reset_obniz_on_ws_disconnection":true}}] (obniz.js, line 7929)
    [Log] Obniz: local connect to ws://192.168.1.32 (obniz.js, line 7929)
    [Log] Obniz: connected to ws://192.168.1.32 (obniz.js, line 7929)
    

    なお、つなごうとしているデバイスは市販品ですが、obnizにつないで使うことはこのメーカが想定している使い方では無いので、ここでの表示は控えます。上記ログで原因判明しない場合は、メールにてご連絡します。
    よろしくお願いします。



  • @nak435 さん

    ログありがとうございます.
    見てみましたが,debugprintBinaryで見れるログでも確認できないようです.

    対象商品について,info@obniz.ioまでご連絡いただけないでしょうか.



  • @kido さん

    試していませんが、
    obniz.js 1.12.2 でconnectできるようになりましたか?



  • @nak435 さん

    すみません、まだ該当商品が使えるようにはなっておりません。

    BLEでの接続までは弊社内で確認ができていますが、BLEのセキュリティ機能がobnizにはまだなく、その先の書き込みができていない状態です。
    現在セキュリティ機能の開発を行っておりますので、もうしばらくお待ちいただけますようお願い致します。



  • @kido さん、了解しました。引き続きよろしくお願いします。



  • @kido さん、ご無沙汰しています。2年放置ですみません。
    本件はどうなったでしょうか?



  • @nak435
    ご無沙汰してます。
    2年前からアップデートがかなりはいっており、単純な比較が難しいですが、
    最新のobnizOSとobnizjsでは、BLEの接続は安定するようになっています。
    セキュリティ関連も対応していますので、おそらく動くのではないかなと思います。


Log in to reply
 

SUGGESTED TOPICS