Pixl.js Bluetooth to Ethernet MQTT Bridge

Pixl.js BLE Ethernet Bridge

This is just a very simple example of using Puck.js to send received Bluetooth LE advertising packets over MQTT to an server.

Just wire up an Arduino WIZnet adaptor as shown on this page then upload the following code with the MQTTSERVER variable set to the IP address of a server running a (non-HTTPS) MQTT server.

To view the received packets, you can run a command such as this if you have the Mosquitto tools installed on your PC:

mosquitto_sub -h -v -t "/advertise"

NOTE: This is a simple example and isn't designed to deal with a large volume of advertising packets. To make this more robust you might want to consider adding a whitelist of BLE addresses that will be forwarded.

Source Code

var MQTTSERVER = "";
var eth, mqtt;
var packets = 0;
var infoInterval;

function onInit() {
  Terminal.println("\n\n"); // add some clear lines
  Terminal.println("Ethernet setup");
  SPI1.setup({ mosi:D11, miso:D12, sck:D13 });
  eth = require("WIZnet").connect(SPI1, D10 /*CS*/);
  eth.setIP(); // DHCP
  Terminal.println("Ethernet ok, "+eth.getIP().ip);
  mqtt = require("MQTT").connect({
    host: MQTTSERVER,
  mqtt.on('connected', function() {
  mqtt.on('disconnected', function() {
    Terminal.println("MQTT disconnected");

function startScan() {
  infoInterval = setInterval(function() {
    Terminal.println((packets/10)+" adverts/sec");
    packets = 0;
  }, 10000);
  NRF.setScan(function(dev) {
    delete dev.data; // we don't want to send the RAW data
    mqtt.publish("/advertise", JSON.stringify(dev));

function stopScan() {
  NRF.setScan(); // stop scanning


This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.