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', () => {})
}
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.
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
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:
Is this expected or am I using the API wrong?