DroidScript App Integration

Posted on
  • I'm looking to create an app for the Bangle that integrates with a phone app so you can control the app via the phone.

    I've got the DroidScript plugin and I can control the Bangle but I'm not sure how best to get it to control the app and not just the Bangle. My only thought is to make the app modify a file stored on the bangle and make the app react to the changes in the file.

    Does anybody else have any better suggestions or something I'm overlooking?

  • So you want to control the Bangle.js app from the phone app? Or the phone app from Bangle.js?

    I'm not entirely sure I understand what you're asking - if you want to send commands to an app that's running, I'd say the easiest method would be to create a function in your Bangle.js app, say called MYAPP.

    You could then call that function using DroidScript and pass whatever data you want to it - for example by sending 'MYAPP({msg:"Hello",data:"World"})\n'

  • Yeah what I'm trying to do is create a tamagotchi style app where the pet lives on the bangle but you use the phone to send the commands to it (feed/play/clean/etc).

    Apologies if these are stupid questions, this is the first time I've used JavaScript for anything other than filling in a form. Loving how instant the feedback is from tweaking a line to having it update on your watch.

  • You got my attention on Tamagochi... perhaps you can start a simple app to feed it with Bangle's buttons, then upgrade that to connect to the phone if that's needed/desired. I'll love to see this in action.

  • Hi Gordon,

    I have this working up to this point. With Droidscript I can call an app function as you outline here.

    I need one more step and that is to return some data from that function back to Droidscript and that has me completely stumped. Is that possible?


  • It might be best to ask on the DroidScript forum - or actually look in the DroidScript app for the Puck.js plugin docs. It's a bit odd but I believe the documentation isn't available online, it's just part of the app.

    I did find this on their forum though:

    You should also be able do basic serial comms with the puck by using the puck.Send( msg ) function and receiving data by setting a callback using the puck.SetOnReceive( callback ) to receive console.log messages coming back from the puck.

    So that could be an option

  • Hi Gordon, Thanks for the quick reply. I eventually worked it out. I want to get some data in real time from a Bangle app onto the android screen.

    In Droidscript

    // Connect to Bangle
      puck = app.CreatePuckJS();
      puck.SetOnReceive( readResponse );   // Callback to capture console output from app.

    The callback function something like :

    function readResponse(data) {
        if ( data.substring(0,1) != '{' ) return;       // ignore non JSON
        d = JSON.parse(data);
      // Do something with the data in array d

    In the Bangle app the dat array is sent as a JSON string :

    function btSend(dat) {
      // console.log(JSON.stringify(dat));         // transmit the data
      Bluetooth.println(JSON.stringify(dat));         // transmit the data

    It will all be published in the 'GPS Adventure Sports II' Bangle app soon.

  • That's great - thanks for posting up the solution!

    Just to add you can use Bluetooth.println instead of console.log in the Bangle app if you want - it outputs direct, so doesn't output some of the other rubbish (the delete character, and > which are used for the REPL)

  • Thanks for the tip. Updated the example above.

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

DroidScript App Integration

Posted by Avatar for Taffaz @Taffaz