Simple client and server

Posted on
  • Hello,

    I received a Puck.js not too long ago and wanted to start using it in some basic tasks that would involve running scripts on my computer, but I have to say I'm kind of at a loss at how to start the process. I'm able to pair the device to my machine and use the IDE easily as well as figure out how to toggle the LEDs and whatnot, but i'm afraid I have no idea how to proceed forward to be able to send custom messages to my paired device (Puck.JS -> Windows 10) in a script.

    The simplest example would be that I want a value (e.g. a number between 0-255) to be sent inside a setWatch() call from Puck.JS, and I want a service on W10 that would be able to receive that call and respond to the received value (e.g. If I received a 1 then run this script, a 2 then run this other script, etc.)

    I thought this would be a common enough use case to have a few examples but I'm having trouble finding anything. Are there any repositories or code examples in the documentation I'm missing that would be able to accomplish this or are there any guides that anyone could point me to that would get me started? It'd be really helpful.

    AFAIK, I would have to become at least a bit knowledgeable on Bluetooth LE protocol itself and terminologies to even get started, which is kind of where I might start soon. I've fallen off of using 'Web Bluetooth' because as far as I understand it, it would require an always active chrome web page up, which if im understanding correctly isn't quite what i'm looking for.

  • Hi,

    It is quite a common thing to want to do, but Bluetooth LE support isn't quite as straightforward as stuff like COM ports and there isn't a nice platform agnostic way to just send data.

    I've tried to write up a lot of the ways of communicating from different languages with examples here: http://www.espruino.com/Interfacing#blue­tooth-le

    Realistically your best bets right now are:

    • Just make Puck.js a Bluetooth HID device like a keyboard. It can then send keypresses that you can pick up with whatever background app you want - or perhaps even send the keypresses needed to run a command directly.
    • Write your own background service that uses BLE directly. What language you use really depends on what you're happy with - but let me know if you're interested in using a language that I didn't cover on that Interfacing page.

  • Tue 2019.10.01

    'are there any guides that anyone could point me to'

    Hello @user103765

    Had searching the forum returned too few results? This link might be a good starting point
    to get some additional ideas. There are link examples that control the web page from the
    Puck that might generate some ideas, or more questions ;-)

    http://forum.espruino.com/conversations/­296979/#13358474

    https://espruino.github.io/puck2.html

    Puck and controlling a web page

    A good launching point from the main site:

    https://www.espruino.com/Web%20Bluetooth­

    A Bi-Directional quick test using the 'Try Me' button near page bottom

    https://www.espruino.com/Web%20Bluetooth­#two-way-communications

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

Simple client and server

Posted by Avatar for user103765 @user103765

Actions