puck-mqtt
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
Running
# connect any pucks found to test.mosquitto.org puck-mqtt # connect to your own server puck-mqtt -h mqtt://test.example.org # 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 toconst MQTT_subs = '/foo/bar' '/baz/foo' '/fez/#'; // helper function for publishing messages { console;} // (implement this) - a handler for incoming messages { console;} // publish events on button press;
How
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:
;thisMQTT_subs||;
Message handlers are called by injecting:
;{ iffn }thisMQTT_handle 'BASE64_ENCODED_TOPIC' 'BASE64_ENCODED_MESSAGE';
Each puck is connected to an individual mqtt connection.
todo
- look at reconnections
- check for handler & subs, display warning if not found
- handle case where > 6 pucks
- live ui
- connection states
- battery levels
Resources
A lot of the connection logic comes via: