Configure Puck to send text to raspberrypi

Posted on
  • Hey,

    I would like to configure my puck to broadcast the temperature, and don't want to use the eddystone protocol, i.e. i don't want to post a url that the user follows in order to see the temp on a website, i just want to broadcast it to a nearby device, like a raspberry with BLE. I'm pretty new to Bluetooth and am still trying to wrap my head around on how to go about this. Ideally i would like to use mqtt and send the data from the puck, to a broker on a raspberry, but that is after i get to send some plain text.

    How would i go about this? Where could i begin?

    PS: I tried puck as an eddystone beacon and it works great! Awesome little device!

  • It's well worth reading this to get a better idea about BLE: http://www.espruino.com/About+Bluetooth+­LE

    You can use advertising to send the temperature, and small amounts of text (a few characters). This does basically what you want - including pushing data over MQTT on a Pi: http://www.espruino.com/Puck.js+Node-RED­

    Otherwise you need a connection. You can keep the Pi permanently connected to a Puck via the UART, but it's not ideal (the most connections a Pi can have open is something like 6).

    You could create a service on the Pi with bleat (or similar) and could then connect from the Puck to the Pi when you had data to send.

    Or the Puck could advertise if it had data ready, and then the Pi could connect to the Puck and request information via UART.

    So there are loads of methods - but Advertising is by far the easiest most power efficient one :)

  • @Gordon is it actually possible to request data via the UART? I thought the UART can send a command but there is no way to receive a response. Would love to see a sample code of a UART response.

  • The UART implementation is two-way, just like a normal serial port. It's how you get the command prompt in the Web IDE. To write to the BLE UART in Espruino, you just use console.log or print - or if you want to do it 'direct' (without it also trying to output the command prompt as well) you can use Bluetooth.write.

    You should be able to find some examples for whatever language you prefer using... For Node.js there's this: https://www.npmjs.com/package/node-uartb­le

    But the library I use for the Web IDE when running under Node.js is: https://github.com/espruino/EspruinoTool­s/blob/gh-pages/core/serial_noble.js

    and the one I use when running under Web Bluetooth is:
    https://github.com/espruino/EspruinoTool­s/blob/gh-pages/core/serial_web_bluetoot­h.js

  • Also the 'puck.js' web bluetooth library that handles two-way comms is here: https://github.com/espruino/espruino.git­hub.io/blob/master/js/puck.js

    It's pretty easy to use: http://www.espruino.com/Puck.js+Web+Blue­tooth

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

Configure Puck to send text to raspberrypi

Posted by Avatar for Attila @Attila

Actions