node package manager
Stop wasting time. Easily manage code sharing in your team. Create a free org »



a hacky BLE & MQTT forwarder.

tl;dr You should use EspruinoHub.

The difference with this:

  • subscribe & publish arbitrary channels on the puck itself
  • limited number of pucks can be connected at one time (depends on OS, maybe 6)
  • likely to be disastrous for battery life


# connect any pucks found to
# connect to your own server
puck-mqtt -h mqtt://
# only connect "Puck.js 1f10" and "Puck.js bf82"
puck-mqtt -p af10 -p bf82
# or, using longer hash (note, no dashes)
puck-mqtt -p 7597340abcdf1097848fd39ecd6291cb12

Puck.js code

// a list of topics to subscribe to 
const MQTT_subs = [
// helper function for publishing messages 
function MQTT_publish(topic, message) {
  console.log("\n<~" + btoa(topic + ' ' + message) + "~>\n");
// (implement this) - a handler for incoming messages 
function MQTT_handle(topic, message) {
  console.log("got a message!", message);
// publish events on button press 
setWatch(function() {
  MQTT_publish('/puck/btn', 'pressed');
}, BTN, { repeat:true, edge:"rising", debounce:50 });


This script creates a BLE UART connection to the puck and listens out for messages of a particular format <~BASE64~>.

Topic subscriptions are read on connect by running:

;(this.MQTT_subs||[]).forEach(s => console.log('\n<~' + btoa(s) + '~>\n'));

Message handlers are called by injecting:

;((fn, a, b)=>{ if(fn) fn(atob(a), atob(b)) })

Each puck is connected to an individual mqtt connection.


  • look at reconnections
  • check for handler & subs, display warning if not found
  • handle case where > 6 pucks
  • live ui
    • connection states
    • battery levels


A lot of the connection logic comes via: