Most recent activity
-
@Gordon is there a reason why the
connection
doesn't have aneval
function? E.g.Puck.connect(conn => { conn.eval('Puck.getBatteryPercentage()', console.log); });
When I run this I get
conn.eval is not a function
. I have tried usingPuck.eval
but it then asks me to reconnect the Puck again. -
-
Hi Gordon,
I found the issue in the https://www.puck-js.com/puck.js code I believe. I've made some comments below.
connection.write = function(data, callback) { // **** This is pushing callback as null **** if (data) txDataQueue.push({data:data,callback:callback}); // *********************** if (connection.isOpen && !connection.txInProgress) writeChunk(); function writeChunk() { var chunk; if (!txDataQueue.length) return; var txItem = txDataQueue[0]; if (txItem.data.length <= CHUNKSIZE) { chunk = txItem.data; txItem.data = undefined; } else { chunk = txItem.data.substr(0,CHUNKSIZE); txItem.data = txItem.data.substr(CHUNKSIZE); } connection.txInProgress = true; log("BT> Sending "+ JSON.stringify(chunk)); txCharacteristic.writeValue(str2ab(chunk)).then(function() { log("BT> Sent"); if (!txItem.data) { txDataQueue.shift(); // **** This is calling the null callback function and throwing an Error. **** txItem.callback(); // *************************** } connection.txInProgress = false; writeChunk(); }).catch(function(error) { log('BT> SEND ERROR: ' + error); txDataQueue = []; // **** The error is being caught and the connection is being closed. **** connection.close(); // ******************** }); } };
Like you said it's an easy fix to only call the callback if one is passed.
-
Hi,
Been playing around with the Web Javascript API and have noticed that if you don't specify a callback on some functions the Puck will disconnect instantly. For example:
Here is what I want to do
let connection; Puck.connect(conn => { conn.write('LED1.set();\n'); connection = conn; }); // Use this function later when a button is clicked const resetLEDOnButtonClick = () => { connection.write('LED1.reset();\n') }
Expect when I call the
resetLEDOnButtonClick
a while later the Puck has been disconnected.I've ended up having to pass empty callbacks everywhere just to stop it disconnecting. For example:
let connection; Puck.connect(conn => { conn.write('LED1.set();\n', () => {}); connection = conn; }); // Use this function later when a button is clicked const resetLEDOnButtonClick = () => { connection.write('LED1.reset();\n', () => {}) }
Is this expected or am I using the API wrong?
-
-
Hi,
I've got my puck up and running using the web IDE but would like to connect and upload code via the command line on OSX. I have followed https://www.espruino.com/Puck.js+Quick+Start#command-line and installed the
espruino
node module andnoble
as well. When I runespruino --list
all I get listed isPORTS: /dev/cu.Bluetooth-Incoming-Port
and no puck addresses.Have I missed something?
Front end JavaScript developer who likes building cool things!