Yes the OS ( raspbian Stretch ) is up to date, i use the noble module to scan the puck when the button is clicked , the code :
// get the mac address of new puckJS - we use noble.js to scan BLE device whose peripheral name is Puck.js then get the mac address and store it
function onDiscovery(peripheral) {
if (peripheral.advertisement.localName == undefined || peripheral.address == 'unknown') {
return;
}
if (peripheral.advertisement.localName.includes("Puck.js")) {
if (peripheral.address == puckJSdevice) {
if (!peripheral.advertisement.manufacturerData ||
peripheral.advertisement.manufacturerData[0] != 0x90 ||
peripheral.advertisement.manufacturerData[1] != 0x05) return;
var data = peripheral.advertisement.manufacturerData.slice(2);
//console.log(data);
if (lastAdvertising[peripheral.address] == undefined) {
lastAdvertising[peripheral.address] = data.toString();
}
// check for changed services
if (lastAdvertising[peripheral.address] != data.toString()) {
console.log(lastAdvertising[peripheral.address], data.toString());
puckClicked.onDeviceChanged(peripheral.address, data);
} else {
currentNumberClicked = data.readInt8(); justOnePass = 0;
}
lastAdvertising[peripheral.address] = data;
}
if (puckJSnoble) {
return;
}
puckJSnoble = peripheral;
if (puckJSdevice) {
return;
} else {
console.log("passage config puck");
puckJSdevice = peripheral.address;
//save the new PuckJS button mac address in the database in tv_config.puckjs
request(serverFamily + '/1.0/tvs/addPuckJSConfig/' + process.env._MAC + '?puckjs=' + puckJSdevice, function (error, res) {
console.log(error || res.message, 'puck button saved');
});
resetScriptPuck();
Then when the clicked button event is triggered i use this code to light the LED ( with espruino ) :
// send command to puck - light the LED
exec('espruino -t -p ' + puckJSdevice + ' -e "LED2.set();"',function(error,stdout,stderr){
console.log("ESPRUINO LIGHT THE LED error : ", error, "stdout : ", stdout, "stderr : ",stderr);
});
On node.js server start i reset and upload this code to puck :
Sometimes it cannot light the led and i have this message : unable to connect "MAC ADDRESS"
or it stop to emit DATA from BLE ( because it still connected to my raspberry controller after the LED is turned on ).
Would it be a solution to force remove the connected puck with "bluetoothctl" before sending the expression with espruino to avoid this? or just waiting a few seconds before trying to connect ?
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Yes the OS ( raspbian Stretch ) is up to date, i use the noble module to scan the puck when the button is clicked , the code :
Then when the clicked button event is triggered i use this code to light the LED ( with espruino ) :
On node.js server start i reset and upload this code to puck :
Sometimes it cannot light the led and i have this message : unable to connect "MAC ADDRESS"
or it stop to emit DATA from BLE ( because it still connected to my raspberry controller after the LED is turned on ).
Would it be a solution to force remove the connected puck with "bluetoothctl" before sending the expression with espruino to avoid this? or just waiting a few seconds before trying to connect ?
Thanks !