-
• #2
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 :)
-
• #4
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
orprint
- 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-uartble
But the library I use for the Web IDE when running under Node.js is: https://github.com/espruino/EspruinoTools/blob/gh-pages/core/serial_noble.js
and the one I use when running under Web Bluetooth is:
https://github.com/espruino/EspruinoTools/blob/gh-pages/core/serial_web_bluetooth.js -
• #5
Also the 'puck.js' web bluetooth library that handles two-way comms is here: https://github.com/espruino/espruino.github.io/blob/master/js/puck.js
It's pretty easy to use: http://www.espruino.com/Puck.js+Web+Bluetooth
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!