-
-
@Gordon yes it's the only new line \n
-
-
-
-
Hi,
My puck.js not advertising anymore, i have changed the battery then the green led flash 5 times sometimes when i click the button.
In a few weeks, The old battery has suddenly lost all its power from ~90% to ~20%.When the battery has died, i changed it with a the same new then impossible to scan it and these flashes started..
What's the meaning of green led flashing ?
Thanks!
here the script uploaded :
`reset(); echo(0); notify(0); clearInterval(); clearWatch(); var presses=0; var timeoutDoubleClick = null; var nbClick = 0; var activeDebug = ""; var releasedTime = 0; var timeoutReleased = null; var switchMode = null; var low = 0; var state = {press : false, release : false}; var batteryLevel = 0; setWatch(function() { state.release = true; state.press = false; if(releasedTime){ activeDebug = "d"; LED.set(); }else{ activeDebug = ""; } nbClick++; if (!timeoutDoubleClick) { timeoutDoubleClick = setTimeout(function(){ timeoutDoubleClick = null; NRF.setAdvertising({},{ interval:150, manufacturer:0x0590, manufacturerData:activeDebug+"clk-"+presses+"-"+nbClick+"-${scriptVersion}-"+batteryLevel }); nbClick = 0; }, 500); } if (nbClick > 1) { clearTimeout(timeoutDoubleClick); timeoutDoubleClick = null; NRF.setAdvertising({},{ interval:150, manufacturer:0x0590, manufacturerData:activeDebug+"clk-"+presses+"-"+nbClick+"-${scriptVersion}-"+batteryLevel }); nbClick = 0; } if(presses > 98){ presses=0; } presses++; }, BTN, {edge:"falling", debounce:20, repeat:1}); setWatch(function(){ state.release = false; state.press = true; if(timeoutReleased){clearTimeout(timeoutReleased);} timeoutReleased = setTimeout(function(){ timeoutReleased = null; if(!state.release){ releasedTime = !releasedTime; var flicker = 0; switchMode = setInterval(function(){ LED.set(); flicker++; setTimeout(function(){ LED.reset(); },150); if(flicker == 3){clearInterval(switchMode);} },300); } },10000) LED.set(); if(!activeDebug){ LED2.reset(); LED3.reset(); } LED.reset(); }, BTN, { edge:'rising', repeat:1, debounce:20 }); LED1.set(); function sendBatteryInfo(){ batteryLevel = Math.round(E.getBattery()); if(batteryLevel < 20){ low = 1;} } sendBatteryInfo(); setInterval(sendBatteryInfo,60 * 60 * 1000); save();\n`
-
-
Hi !
i would like to set in puck.js a reserved address with NRF.on('connect',function(addr){})
But i don't know what is the address ( which devices MAC address ? ) i use a Raspberry pi 3 B.
Is it the mac address of the bluetooth controller? i have already tested with it but it does not work.. maybe i have not correctly write it in my code.Thank You !
-
-
-
-
Hi!
I have uploaded a script which set data on button click.
Here is the code :echo(0);\n clearInterval(); clearWatch(); var presses = 0;\n setWatch(function () {\n if(presses > 100) { presses = 0; }\n presses++;\n LED2.reset();\n LED3.reset();\n NRF.setAdvertising({}, { interval: 200, manufacturer: 0x0590, manufacturerData: [presses] });\n }, BTN, { edge: 'falling', repeat: 1, debounce: 0 })\n LED1.set()\n setTimeout(function () { LED1.reset() }, 2000)\n save();
It works fine but sometimes when i click the button.. noble.js does not scan any changed data.
However the data value has changed but not advertised. ( it means the setWatch function is working )
I think it's a problem in puck.js script updated.. maybe NRF.setAdvertising ?It is a major problem for our application. Do you have any idea of what could cause this issue ?
Thank you ! -
-
-
I'm on Raspbian Stretch,
Here the code from my app :if (puckJSnoble) { puckJSnoble.connect() puckJSnoble.once('connect', () => { puckJSnoble.discoverAllServicesAndCharacteristics(function ( error, services, characteristics ) { var txCharacteristic = findByUUID(characteristics, NORDIC_TX) var rxCharacteristic = findByUUID(characteristics, NORDIC_RX) console.log("passage connected"); if (txCharacteristic && rxCharacteristic) { rxCharacteristic.subscribe(function () { try { var writeData = () => { splitTheScript(scriptInit) setTimeout(() => { txCharacteristic.write( stringToBuffer(splittedScript), false, function (error) { if (error) { console.log( 'error writing data in puck - init : ', error ) } if (splitFinished == true) { rxCharacteristic.unsubscribe(error => { // console.log('unsubscribe : ', error) puckJSnoble.disconnect(error => { console.log(error) }) }) splitFinished = false } else { writeData() } } ) }, delayWrite) } if (!reseted) { txCharacteristic.write( stringToBuffer('reset()\nsave()'), false, function (error) { puckJSnoble.disconnect(error => { console.log(error) }) } ) } else { writeData(); } } catch (e) { console.log('BT> SEND ERROR ' + e) } }) } }) }) puckJSnoble.once('disconnect', () => { console.log('PASSAGE disconnect') if (reseted) { noble.startScanning([], true) } else { reseted = true; initPuck(); cbStopScanning(); } }) } // Converts a string to a Buffer function stringToBuffer(str) { // console.log(str); var buf = new Buffer(str.length) for (var i = 0; i < buf.length; i++) { buf.writeUInt8(str.charCodeAt(i), i) } console.log('buffer : ', buf) return buf } // split the script every 19 byte (device's limit..) to write data in puck.js function splitTheScript(data) { var writeData = [{ data: data, blockSize: 19 }] var d var split = writeData[0].nextSplit || { start: 0, end: writeData[0].data.length, delay: 0 } // Otherwise split based on block size if (split.end >= writeData[0].blockSize) { split = { start: 0, end: writeData[0].blockSize, delay: 0 } } else { splitFinished = true } // Only send some of the data if (writeData[0].data.length > split.end) { if (split.delay == 0) split.delay = 50 d = writeData[0].data.substr(0, split.end) writeData[0].data = writeData[0].data.substr(split.end) if (writeData[0].nextSplit) { writeData[0].nextSplit.start -= split.end writeData[0].nextSplit.end -= split.end if (writeData[0].nextSplit.end <= 0) writeData[0].nextSplit = undefined } } else { d = writeData[0].data writeData[0].data = '' writeData[0].nextSplit = undefined } // actually write data scriptInit = writeData[0].data splittedScript = d delayWrite = split.delay console.log( 'Sending block ' + JSON.stringify(d) + ', wait ' + split.delay + 'ms' ) }
-
Hi, sometimes when i want to upload buffer code to puck.js, it stuck in middle of uploading.
I use noble.js, i connect to the puck then convert the code splitted every 19 bytes to write each splitted code to puck.
Sometimes the uploads stop and i cannot reconnect to the puck , i must force reset it to be able to reconnect..sample code :
0|server | Sending block "clearInterval();cle", wait 50ms 0|server | buffer : <Buffer 63 6c 65 61 72 49 6e 74 65 72 76 61 6c 28 29 3b 63 6c 65> 0|server | Sending block "arWatch();var press", wait 50ms 0|server | buffer : <Buffer 61 72 57 61 74 63 68 28 29 3b 76 61 72 20 70 72 65 73 73> 0|server | Sending block "es=0;\nsetWatch(func", wait 50ms 0|server | buffer : <Buffer 65 73 3d 30 3b 0a 73 65 74 57 61 74 63 68 28 66 75 6e 63>
i have tested with a delay of 100ms and it change nothing..
when the upload works :
0|server | Sending block "clearInterval();cle", wait 50ms 0|server | buffer : <Buffer 63 6c 65 61 72 49 6e 74 65 72 76 61 6c 28 29 3b 63 6c 65> 0|server | Sending block "arWatch();var press", wait 50ms 0|server | buffer : <Buffer 61 72 57 61 74 63 68 28 29 3b 76 61 72 20 70 72 65 73 73> 0|server | Sending block "es=0;\nsetWatch(func", wait 50ms 0|server | buffer : <Buffer 65 73 3d 30 3b 0a 73 65 74 57 61 74 63 68 28 66 75 6e 63> 0|server | Sending block "tion(){\nif(presses ", wait 50ms 0|server | buffer : <Buffer 74 69 6f 6e 28 29 7b 0a 69 66 28 70 72 65 73 73 65 73 20> 0|server | Sending block "> 100){presses=0;}\n", wait 50ms 0|server | buffer : <Buffer 3e 20 31 30 30 29 7b 70 72 65 73 73 65 73 3d 30 3b 7d 0a> 0|server | Sending block "presses++;\nLED2.res", wait 50ms 0|server | buffer : <Buffer 70 72 65 73 73 65 73 2b 2b 3b 0a 4c 45 44 32 2e 72 65 73> 0|server | Sending block "et();\nLED3.reset();", wait 50ms 0|server | buffer : <Buffer 65 74 28 29 3b 0a 4c 45 44 33 2e 72 65 73 65 74 28 29 3b> 0|server | Sending block "\nNRF.setAdvertising", wait 50ms 0|server | buffer : <Buffer 0a 4e 52 46 2e 73 65 74 41 64 76 65 72 74 69 73 69 6e 67> 0|server | Sending block "({},{manufacturer:0", wait 50ms 0|server | buffer : <Buffer 28 7b 7d 2c 7b 6d 61 6e 75 66 61 63 74 75 72 65 72 3a 30> 0|server | Sending block "x0590,manufacturerD", wait 50ms 0|server | buffer : <Buffer 78 30 35 39 30 2c 6d 61 6e 75 66 61 63 74 75 72 65 72 44> 0|server | Sending block "ata:[presses]});\n},", wait 50ms 0|server | buffer : <Buffer 61 74 61 3a 5b 70 72 65 73 73 65 73 5d 7d 29 3b 0a 7d 2c> 0|server | Sending block "BTN,{edge:'rising',", wait 50ms 0|server | buffer : <Buffer 42 54 4e 2c 7b 65 64 67 65 3a 27 72 69 73 69 6e 67 27 2c> 0|server | Sending block "repeat:1,debounce:5", wait 50ms 0|server | buffer : <Buffer 72 65 70 65 61 74 3a 31 2c 64 65 62 6f 75 6e 63 65 3a 35> 0|server | Sending block "0})\nLED1.set()\nsetT", wait 50ms 0|server | buffer : <Buffer 30 7d 29 0a 4c 45 44 31 2e 73 65 74 28 29 0a 73 65 74 54> 0|server | Sending block "imeout(function(){L", wait 50ms 0|server | buffer : <Buffer 69 6d 65 6f 75 74 28 66 75 6e 63 74 69 6f 6e 28 29 7b 4c> 0|server | Sending block "ED1.reset()},2000)\n", wait 50ms 0|server | buffer : <Buffer 45 44 31 2e 72 65 73 65 74 28 29 7d 2c 32 30 30 30 29 0a> 0|server | Sending block "save()", wait 0ms 0|server | buffer : <Buffer 73 61 76 65 28 29>
the full javascript code :
clearInterval();clearWatch();var presses=0;\nsetWatch(function(){\nif(presses > 100){presses=0;}\npresses++;\nLED2.reset();\nLED3.reset();\nNRF.setAdvertising({},{manufacturer:0x0590,manufacturerData:[presses]});\n},BTN,{edge:'rising',repeat:1,debounce:50})\nLED1.set()\nsetTimeout(function(){LED1.reset()},2000)\nsave()
Thank You!
-
-
-
-
-
-
-
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 :
var presses = 0; setWatch(function() { if(presses > 100){presses=0} presses++; LED2.reset(); LED3.reset(); NRF.setAdvertising({},{manufacturer: 0x0590, manufacturerData:[presses]}); }, BTN, {edge:"rising", repeat:1, debounce:50})
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 !
-
Hello, i have a problem with the command line Espruino and noble in my node.js server.
When i want to disconnect et reconnect my device, it often stuck in 'connecting' status.
I'm working with a Raspberry Pi 3 B+ with Raspbian Stretch OS.my HCIDUMP when i connect device with some code sent to puck.js :
HCI sniffer - Bluetooth packet analyzer ver 5.43 device: hci0 snap_len: 1500 filter: 0xffffffff > HCI Event: Command Status (0x0f) plen 4 Disconnect (0x01|0x0006) status 0x00 ncmd 1 > HCI Event: Disconn Complete (0x05) plen 4 status 0x00 handle 64 reason 0x16 Reason: Connection Terminated by Local Host > HCI Event: Command Complete (0x0e) plen 4 LE Set Scan Enable (0x08|0x000c) ncmd 1 status 0x0c Error: Command Disallowed > HCI Event: Command Complete (0x0e) plen 4 Set Event Mask (0x03|0x0001) ncmd 1 status 0x00 > HCI Event: Command Complete (0x0e) plen 4 LE Set Event Mask (0x08|0x0001) ncmd 1 status 0x00 > HCI Event: Command Complete (0x0e) plen 12 Read Local Version Information (0x04|0x0001) ncmd 1 status 0x00 HCI Version: 4.1 (0x7) HCI Revision: 0x8b LMP Version: 4.1 (0x7) LMP Subversion: 0x6119 Manufacturer: Broadcom Corporation (15) > HCI Event: Command Complete (0x0e) plen 4 Write LE Host Supported (0x03|0x006d) ncmd 1 > HCI Event: Command Complete (0x0e) plen 6 Read LE Host Supported (0x03|0x006c) ncmd 1 > HCI Event: Command Complete (0x0e) plen 10 Read BD ADDR (0x04|0x0009) ncmd 1 status 0x00 bdaddr B8:27:EB:DC:0C:65 > HCI Event: Command Complete (0x0e) plen 4 LE Set Scan Enable (0x08|0x000c) ncmd 1 status 0x0c Error: Command Disallowed > HCI Event: Command Complete (0x0e) plen 4 LE Set Scan Parameters (0x08|0x000b) ncmd 1 status 0x00 > HCI Event: Command Complete (0x0e) plen 4 LE Set Scan Enable (0x08|0x000c) ncmd 1 status 0x0c Error: Command Disallowed > HCI Event: Command Complete (0x0e) plen 4 LE Set Scan Parameters (0x08|0x000b) ncmd 1 status 0x00 > HCI Event: Command Complete (0x0e) plen 4 LE Set Scan Enable (0x08|0x000c) ncmd 1 status 0x00 > HCI Event: Command Complete (0x0e) plen 4 LE Set Scan Enable (0x08|0x000c) ncmd 1 status 0x00 > HCI Event: Command Status (0x0f) plen 4 LE Create Connection (0x08|0x000d) status 0x00 ncmd 1 > HCI Event: Command Status (0x0f) plen 4 LE Read Remote Used Features (0x08|0x0016) status 0x00 ncmd 1 > HCI Event: Command Complete (0x0e) plen 14 LE Read Remote Used Features (0x08|0x0016) ncmd 1
then when i want to disconnect and reconnect with another code
> HCI Event: Command Status (0x0f) plen 4 Disconnect (0x01|0x0006) status 0x00 ncmd 1 > HCI Event: Disconn Complete (0x05) plen 4 status 0x00 handle 64 reason 0x16 Reason: Connection Terminated by Local Host > HCI Event: Command Complete (0x0e) plen 4 LE Set Scan Enable (0x08|0x000c) ncmd 1 status 0x0c Error: Command Disallowed > HCI Event: Command Complete (0x0e) plen 4 LE Set Scan Enable (0x08|0x000c) ncmd 1 status 0x0c Error: Command Disallowed > HCI Event: Command Complete (0x0e) plen 4 Set Event Mask (0x03|0x0001) ncmd 1 status 0x00 > HCI Event: Command Complete (0x0e) plen 4 LE Set Event Mask (0x08|0x0001) ncmd 1 status 0x00 > HCI Event: Command Complete (0x0e) plen 12 Read Local Version Information (0x04|0x0001) ncmd 1 status 0x00 HCI Version: 4.1 (0x7) HCI Revision: 0x8b LMP Version: 4.1 (0x7) LMP Subversion: 0x6119 Manufacturer: Broadcom Corporation (15) > HCI Event: Command Complete (0x0e) plen 4 Write LE Host Supported (0x03|0x006d) ncmd 1 > HCI Event: Command Complete (0x0e) plen 6 Read LE Host Supported (0x03|0x006c) ncmd 1 > HCI Event: Command Complete (0x0e) plen 10 Read BD ADDR (0x04|0x0009) ncmd 1 status 0x00 bdaddr B8:27:EB:DC:0C:65 > HCI Event: Command Complete (0x0e) plen 4 LE Set Scan Enable (0x08|0x000c) ncmd 1 status 0x0c Error: Command Disallowed > HCI Event: Command Complete (0x0e) plen 4 LE Set Scan Parameters (0x08|0x000b) ncmd 1 status 0x00 > HCI Event: Command Complete (0x0e) plen 4 LE Set Scan Enable (0x08|0x000c) ncmd 1 status 0x0c Error: Command Disallowed >
the Espruino command line tool STDERR :
noble warning: unknown handle 64 disconnected!
Port "c6:93:50:de:bc:bd" not found
Unable to connect!It seems like puck.js stay connected with my bluetooth controler after a simple espruino command
"espruino -t -p c6:93:50:de:bc:bd -e 'LED3.set();'"Thanks !
Hi !
I have encountered on many puck.js buttons 2.0 only, a hardware problem.
The battery base was unsoldered on one side..
I had this issue on about ten buttons ..
It happen after the battery was inserted.
The battery base is more narrow than 1.0 and i feel that we have to force more to put the battery inside the base..
has other users encountered this issue ?
What can you do ? maybe this issue is corrected since ?
Thank you