Programming puck using native android app code.

Posted on
  • Hi All,

    We are having some requirement of using the android app(Native). Is it possible to write the js code on puckjs device using the android native app on first configuration. Please help us .

    Thanks
    Harminder Singh

  • Yes, that's not a problem at all. There some 'Nordic UART' example code for Android provided by Nordic Semiconductor (or you can just do it yourself by writing to the Nordic UART bluetooth characteristics).

    You can just connect, and then write JavaScript code straight to the Bluetooth UART. It'll then be executed after a newline. There's a very rough example here using Web Bluetooth: http://www.espruino.com/Puck.js+Web+Blue­tooth#two-way-communications

    In that example, when connected, it calls reset() to reset the device, and then uploads a line of JS code that'll write data out a few times a second. Something like that can easily be extended for more complex code.

    If you have other questions about it don't hesitate to ask though!

    (edit: just moving this to the Puck.js forum)

  • Thanks @Gordon let me try this :)

  • @Gordon I was able to connect to device. And it works for one command. But i am not able to send a complete script. Can you share me some sample if possible how to pass the data to device in complex code. I have 100 +line of js. What is the best way to send data.

    When i write this code to puck it didn't do anything

  • Ahh, ok. Your problem could be that by default Espruino is acting as a normal command-line interface. It 'echo's the characters you send it back to you, and that could be causing buffering problems since it may be trying to send more characters to you than you are to it.

    One way to debug would be to make sure you set notifications on the RX characteristic, and dump the data you receive back from Puck.js somewhere so you can see if you get any errors.

    You can either send echo(0)\n to stop echoing, or you can prefix each statement you send with \x10 (char code 16) to stop it on a per-statement basis.

    The other easy solution to this is to run your code through the Espruino command-line tools: https://www.npmjs.com/package/espruino

    If you do espruino -p puck_bluetooth_address myfile.js -o output.js then it'll output the exact text that the IDE would have sent to Puck.js - you can then send that slightly modified text over yourself.

  • Thanks @Gordon but didn't get much help with above code. when i write the code the device line by line it start executing the code.

    if complete code is written in single step then nothing happens.

  • Do you think you can give me a short example of what you're sending, what's happening, and what you expect to happen?

    Usually when you send code to Espruino (for instance via the Web IDE) it is executed as it is uploaded. If you don't want it to execute then you put the code inside a function, and then you call that function when you need the code executed.

  • Thanks @Gordon i got the issue was the amount of data sent to device. I have read android documentation that it allows 20bytes as MTU which was the issues in my case i have broken the code into chunks and send it to device and it worked (y)

  • Great! Thanks for letting us know how you got it sorted!

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

Programming puck using native android app code.

Posted by Avatar for Harry @Harry

Actions