Hi @ralle, in the case where you have more than one Raspberry Pi acting as a BLE sniffer, you would:
- designate one Pi to be the “central” instance, and have it perform the MQTT forwarding
- have the other Pis forward their real-time data to the “central” instance via our barnaclesrest service
Central Instance
Put the following in a file called server.js and from the command line run “node server.js”.
// User-defined
var CLIENT_OPTIONS = { /* MQTT client options go here */ }
var TOPIC = 'topic/goes/here';
var HOSTNAME = 'ip-address-goes-here';
// Fire up the reelyActive hyperlocal context server
var server = require('hlc-server');
var app = new server();
// Listen on the BLE radio of the Pi 3
app.bind( { protocol: 'hci', path: 'null' } );
// Set up the MQTT client service
app.addNotificationService( {
service: "barnaclesmqtt",
hostname: HOSTNAME,
topic: TOPIC,
clientOptions: CLIENT_OPTIONS
});
Other Instances
Put the following in a file called server.js and from the command line run “node server.js”. Don’t forget to update the IP address of the “central” instance below:
// Fire up the reelyActive hyperlocal context server
var server = require('hlc-server');
var app = new server();
// Listen on the BLE radio of the Pi 3
app.bind( { protocol: 'hci', path: 'null' } );
// Set up the barnacles REST forwarding service
app.addNotificationService( {
service: "barnaclesrest",
hostname: "192.168.1.101", // IP address of central instance
port: 3001
});
Remember that before running that code on the Pis you’ll need to install the requisite Node.js packages from the command line:
npm install hlc-server
npm install bluetooth-hci-socket
npm install mqtt
How do you check if it’s working? Browse to the “central” Pi, port 3001, for instance http://192.168.1.101:3001, and you should see the Hyperlocal Context webpage and packets coming in. You can browse the web APIs to confirm that data from all Pis is being received.
Hope that helps! Note that we’ve recently added an SD card image with just about everything pre-installed to our Make a Raspberry Pi Hub Tutorial.