Communication between browser and bangle.js.

Posted on
  • I want to use bluetooth to communicate between a browser and bangle.js. I want to scan a QR code and send the scan information from the browser to bangle.js. I was able to create a program for the browser side using the web bluetooth api, but I am unable to create a program for the bangle.js side. Is there a sample that might be helpful?

  • Hi,

    There's a tutorial on Web Bluetooth with Espruino devices on http://www.espruino.com/Web+Bluetooth which may help, but it sounds like you have the Web Bluetooth side sorted?

    There are a bunch of tutorials for apps at https://www.espruino.com/Bangle.js#tutor­ials but lets say in the simplest case you have some data object you want to save to Bangle.js's memory and then load it in your app...

    In your Web Bluetooth code, send some text like "\x03\x10require("Storage").writeJSON("m­yapp.settings.js",{my:1,json:2,data:3})"­ - you probably want the command "\x03\x10require("Storage").writeJSON("m­yapp.settings.js","+JSON.stringify(myjso­ndata)+")"

    Then in the app, just use var mydata = require("Storage").readJSON("myapp.setti­ngs.js",1); and you can access mydata.data/etc

  • Hi,
    Thank you for your answer.
    I don't have much knowledge of programming, so please teach me.

    The content of http://www.espruino.com/Web+Bluetooth looks like a sample for puck.js, such as "Puck.write".

    I want to send text from my browser to bangle.js via bluetooth and have it appear on the bangle.js screen.
    Currently, the browser-side program (write_test.html in the attachment) uses the bluejelly library.
    On the browser side, writing from the connection works fine, but I can't figure out how to receive it on the bangle.js side.

    I don't know how to write "\x03\x10require("Storage").writeJSON("m­yapp.settings.js", "+JSON.stringify(myjsondata)+")" on my program. Is there a simple sample program?

    I'm looking forward to working with you.


    1 Attachment

  • I'm sorry, I misunderstood.
    I see that Puck.write can also be used in bangle.js.
    I was able to achieve this by reading and writing to variables using Puck.write and Puck.eval. Thank you very much.

  • Yes, Puck was the first Bluetooth Espruino, so I guess that's where the name comes from. But can be used with any Bluetooth Espruino (Puck.js, Pixl.js, MDBT42Q breakout, Bangle.js)
    Or I maybe even with any Bluetooth device that implements the Nordic Uart Service...

  • I guess that's where the name comes from

    It's a bit confusing! Yes, unfortunately when I was doing Puck.js I wasn't planning on other devices, so I didn't think to name the library in a more sensible way!

  • I got the impression that the uart.js is the preferred one to use over puck.js now. It covers a bit more like serial/usb but otherwise is same as puck and maybe with a bit less misleading legacy name.

  • I got the impression that the uart.js is the preferred one to use over puck.js now

    Yes, that's true - however right now if you only want to connect to bluetooth it's a bit frustrating having the prompt appear for Bluetooth/Serial. It's something I need to get changed.

  • It would be nice if the bluetooth connection could be made without prompting.

  • Sadly it's part of the Web Bluetooth spec. At least the first time you connect, the website has to prompt you (it's a security thing).

    It is possible to handle subsequent connects to the same device without a prompt I believe, but realistically that is something that you may need to handle yourself with Web Bluetooth.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Communication between browser and bangle.js.

Posted by Avatar for user124233 @user124233

Actions