WebBluetooth Failing a Write Characteristic on Windows but not OSX











up vote
2
down vote

favorite












I'm trying to send a sample hex string to a BLE device via web bluetooth.



This string is sending perfectly fine on OSX, but when I attempt to send it on windows I'm getting the following error:



Uncaught (in promise) DOMException: GATT operation failed for unknown reason.


Here is the code I'm using to send the string and convert it:



        event.target.writeValue(str2ab(":100000000C9434000C943E000C943E000C943E0082*"));


Here is my str2ab function:



 function str2ab(str) {
var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
var bufView = new Uint16Array(buf);
for (var i=0, strLen=str.length; i<strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}









share|improve this question


















  • 1




    I'm seeing the same problems on Windows also, you aren't alone!
    – EL45
    Nov 7 at 21:30










  • @EL45 I've narrowed the problem down to being that on Windows you can only send 20 bytes at a time! I'll rewrite the way I'm sending data and post it as a solution.
    – Wezley
    Nov 7 at 23:09










  • @EL45 I just posted a fix!
    – Wezley
    Nov 8 at 1:49















up vote
2
down vote

favorite












I'm trying to send a sample hex string to a BLE device via web bluetooth.



This string is sending perfectly fine on OSX, but when I attempt to send it on windows I'm getting the following error:



Uncaught (in promise) DOMException: GATT operation failed for unknown reason.


Here is the code I'm using to send the string and convert it:



        event.target.writeValue(str2ab(":100000000C9434000C943E000C943E000C943E0082*"));


Here is my str2ab function:



 function str2ab(str) {
var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
var bufView = new Uint16Array(buf);
for (var i=0, strLen=str.length; i<strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}









share|improve this question


















  • 1




    I'm seeing the same problems on Windows also, you aren't alone!
    – EL45
    Nov 7 at 21:30










  • @EL45 I've narrowed the problem down to being that on Windows you can only send 20 bytes at a time! I'll rewrite the way I'm sending data and post it as a solution.
    – Wezley
    Nov 7 at 23:09










  • @EL45 I just posted a fix!
    – Wezley
    Nov 8 at 1:49













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm trying to send a sample hex string to a BLE device via web bluetooth.



This string is sending perfectly fine on OSX, but when I attempt to send it on windows I'm getting the following error:



Uncaught (in promise) DOMException: GATT operation failed for unknown reason.


Here is the code I'm using to send the string and convert it:



        event.target.writeValue(str2ab(":100000000C9434000C943E000C943E000C943E0082*"));


Here is my str2ab function:



 function str2ab(str) {
var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
var bufView = new Uint16Array(buf);
for (var i=0, strLen=str.length; i<strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}









share|improve this question













I'm trying to send a sample hex string to a BLE device via web bluetooth.



This string is sending perfectly fine on OSX, but when I attempt to send it on windows I'm getting the following error:



Uncaught (in promise) DOMException: GATT operation failed for unknown reason.


Here is the code I'm using to send the string and convert it:



        event.target.writeValue(str2ab(":100000000C9434000C943E000C943E000C943E0082*"));


Here is my str2ab function:



 function str2ab(str) {
var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
var bufView = new Uint16Array(buf);
for (var i=0, strLen=str.length; i<strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}






javascript google-chrome bluetooth web-bluetooth






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 7 at 17:09









Wezley

1081113




1081113








  • 1




    I'm seeing the same problems on Windows also, you aren't alone!
    – EL45
    Nov 7 at 21:30










  • @EL45 I've narrowed the problem down to being that on Windows you can only send 20 bytes at a time! I'll rewrite the way I'm sending data and post it as a solution.
    – Wezley
    Nov 7 at 23:09










  • @EL45 I just posted a fix!
    – Wezley
    Nov 8 at 1:49














  • 1




    I'm seeing the same problems on Windows also, you aren't alone!
    – EL45
    Nov 7 at 21:30










  • @EL45 I've narrowed the problem down to being that on Windows you can only send 20 bytes at a time! I'll rewrite the way I'm sending data and post it as a solution.
    – Wezley
    Nov 7 at 23:09










  • @EL45 I just posted a fix!
    – Wezley
    Nov 8 at 1:49








1




1




I'm seeing the same problems on Windows also, you aren't alone!
– EL45
Nov 7 at 21:30




I'm seeing the same problems on Windows also, you aren't alone!
– EL45
Nov 7 at 21:30












@EL45 I've narrowed the problem down to being that on Windows you can only send 20 bytes at a time! I'll rewrite the way I'm sending data and post it as a solution.
– Wezley
Nov 7 at 23:09




@EL45 I've narrowed the problem down to being that on Windows you can only send 20 bytes at a time! I'll rewrite the way I'm sending data and post it as a solution.
– Wezley
Nov 7 at 23:09












@EL45 I just posted a fix!
– Wezley
Nov 8 at 1:49




@EL45 I just posted a fix!
– Wezley
Nov 8 at 1:49












1 Answer
1






active

oldest

votes

















up vote
1
down vote













So it looks like for windows you have a 20 byte limit.



To correct the issue I'm using a write buffer and recursively going over it until all the bites have been written. Here is the code.



function writeBuffer(string) {
writeOut(string, 0);
}

function writeOut(string, start) {
if(start >= string.length) return;
myCharacteristic.writeValue(str2ab(string.substring(start, (start+20)))).then(foo => {
writeOut(string, (start+20));
});
}





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53194416%2fwebbluetooth-failing-a-write-characteristic-on-windows-but-not-osx%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    So it looks like for windows you have a 20 byte limit.



    To correct the issue I'm using a write buffer and recursively going over it until all the bites have been written. Here is the code.



    function writeBuffer(string) {
    writeOut(string, 0);
    }

    function writeOut(string, start) {
    if(start >= string.length) return;
    myCharacteristic.writeValue(str2ab(string.substring(start, (start+20)))).then(foo => {
    writeOut(string, (start+20));
    });
    }





    share|improve this answer

























      up vote
      1
      down vote













      So it looks like for windows you have a 20 byte limit.



      To correct the issue I'm using a write buffer and recursively going over it until all the bites have been written. Here is the code.



      function writeBuffer(string) {
      writeOut(string, 0);
      }

      function writeOut(string, start) {
      if(start >= string.length) return;
      myCharacteristic.writeValue(str2ab(string.substring(start, (start+20)))).then(foo => {
      writeOut(string, (start+20));
      });
      }





      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        So it looks like for windows you have a 20 byte limit.



        To correct the issue I'm using a write buffer and recursively going over it until all the bites have been written. Here is the code.



        function writeBuffer(string) {
        writeOut(string, 0);
        }

        function writeOut(string, start) {
        if(start >= string.length) return;
        myCharacteristic.writeValue(str2ab(string.substring(start, (start+20)))).then(foo => {
        writeOut(string, (start+20));
        });
        }





        share|improve this answer












        So it looks like for windows you have a 20 byte limit.



        To correct the issue I'm using a write buffer and recursively going over it until all the bites have been written. Here is the code.



        function writeBuffer(string) {
        writeOut(string, 0);
        }

        function writeOut(string, start) {
        if(start >= string.length) return;
        myCharacteristic.writeValue(str2ab(string.substring(start, (start+20)))).then(foo => {
        writeOut(string, (start+20));
        });
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 8 at 1:48









        Wezley

        1081113




        1081113






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53194416%2fwebbluetooth-failing-a-write-characteristic-on-windows-but-not-osx%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini