• hi,

    I want a wireless door bell with the puck-js as the button, and when pressed it can play music (MP3 or whatever sound it can make) from a Andriod phone or tablet inside the house.

    Sorry I am a very beginner of programming puck js, any suggestions are welcomed thanks

  • Hi, that sounds like a fun project!

    I guess the easiest solution would be to set Puck.js up as a Bluetooth keyboard: http://www.espruino.com/Puck.js+Keyboard­

    If you follow the 'Multimedia Keys' example you can make it act like a 'Play' button - so any music that was queued up on the phone would then play - without needing any software on the phone itself.

    To go a little further you could turn Puck.js into a normal keyboard and make an app (or just a website) that listened for any keypress, and then did whatever you wanted (play music, etc).

    If you wanted to go further I think you'd definitely need to write an app on the Android phone though. Have you ever done anything like that?

    The best solution would be for an app to scan for Bluetooth advertisement data (so there was no active connection needed) - which it could do even while the phone's screen was off.

    Hope that helps!

  • Thanks Gordon for your prompt reply.

    No unfortunately I have no experience on andriod app (very long time ago I did take a class about window mobile programming, i think ~20yrs ago...). Can you point me direction where to start with? If I want this work I definitely need it to be working while the phone's screen is off.

  • To be fair the play button would work with the phone off - and it could stop the music after a few seconds as well. It's just a matter of keeping music queued up - but you could probably find something for that.

    For Android app development, best to check out Google's site: https://developer.android.com/training/i­ndex.html

    You could have a go at following their tutorial to do a really simple app, and see how you feel about it?

  • If you Google SL4A Scripting Language for Android

    https://en.wikipedia.org/wiki/Scripting_­Layer_for_Android

    Write code in Python, HTML and JavaScript to access Android features including Bluetooth.
    I have an older version and do the editing on my PC and use Samsung Kies to move the files over to my tablet. Some stuff I've done in Python only, others I use the Python to display an HTML page from the SD card and then use JavaScript scripts to do stuff like speak, access Bluetooth or access the Web. All of the Android facades are accessible.

    http://www.mithril.com.au/android/doc/

    Attached two files as an example.


    2 Attachments

  • hi Gordon,

    sorry its really my first project on my puck js. I run through the tutorial and run some basic command like checking battery percentage, light level etc without problem. But when I try the multimedia keys code, I realised I need the ble_hid_controls.js code which I tried to send it to my puck js. However when I did that I got the following errors (see print screen).


    1 Attachment

    • puckjs1.jpg
  • No problem! All you need to do is put (only) the multimedia keys code on the right-hand side of the IDE:

    var controls = require("ble_hid_controls");
    NRF.setServices(undefined, { hid : controls.report });
    
    // Play/stop music
    controls.playpause();
    
    // Send 'volume up' twice
    controls.volumeUp(function() {
      controls.volumeUp();
    });
    

    Then, click the upload button and the ble_hid_controls js file will be automatically loaded in for you :)

  • Hi Gordon,

    Yes I did that, but it got some other problem...


    1 Attachment

    • 2017-06-15 (3).png
  • Bluetooth HID can't be enabled while your Bluetooth connection is still active. To make it work you need to upload the code, disconnect, and then reconnect using your operating system's 'Pair' functionality. After that, pressing the button should work fine.

  • Hi Gordon, I upload the code via my desktop, then I disconnect it. I reconnect the puck to my mobile via Bluetooth pairing. But after I did the pairing, the button still didn't work. I notice my Bluetooth pairing got a message as attached


    1 Attachment

    • Screenshot_20170616-114016.png
  • That's a really weird message - I've never seen that before. You're not using your phone as an input device for something else are you?

    What if you try and pair on your Mac? It should work as an input device there.

  • I tried that with a iphone, but still no luck... but I didnt see any problem with the pairing.

    The android phone I am using is samsung s8+

    I also try to do that with my window 10 surface book, but i failed to pair up the puck js with it. It said "Setup incomplete because of a metered connection"

  • "Setup incomplete because of a metered connection" seems to imply that Windows was trying to get drivers for Puck.js but your internet connection had been set to 'metered' so downloads were being restricted.

    https://www.tenforums.com/network-sharin­g/63186-metered-wifi-bluetooth.html

    Is it possible you'd done that?

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

Play music (MP3) from a Andriod phone when the button is pressed

Posted by Avatar for ac @ac

Actions