• Hi,

    I've tried the suggested fix with little success, attached is my code:

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    
        <script src="https://www.puck-js.com/puck.js">
            var connection;
            document.getElementById("btnId").addEven­tListener("click", function () {
                if (connection) {
                    connection.close();
                    connection = undefined;
                }
    
                Puck.connect(function (c) {
                    if (!c) {
                        alert("Couldn't connect!");
                        return;
                    }
    
                    connection = c;
    
                    function connectDevice() {
    
                        connection.write("reset();\n", function () {
                            // Wait for it to reset itself
                            setTimeout(function () {
                                connection.write(`
                                var zero = Puck.mag();
                                var rep = 0;
    
                                function onMag(p) {
                                    p.x -= zero.x;
                                    p.y -= zero.y;
                                    p.z -= zero.z;
                                    var s = Math.sqrt(p.x * p.x + p.y * p.y + p.z * p.z);
                                    if (!Boolean(s < 1000)) {
                                        digitalPulse(LED2, 1, 1000);
                                        rep++;
                                        Bluetooth.println(rep);
                                    }
                                }
                                Puck.on('mag', onMag);
                                Puck.magOn(); `,
                                    function () { console.log("Ready..."); });
                            }, 1500);
                        })
                    }
    
                });
            });
    
        </script>
    </head>
    
    <body>
        <button id="btnId" onclick="Puck.connect()">On!</button>
        <button onclick="Puck.write('LED1.reset();\n');"­>Off!</button>
    </body>
    
    </html>
    

    I've tried this line:

    <button id="btnId" onclick="Puck.connect()">On!</button>
    

    With and without the onclick attribute. Whenever it connects to the Puck it follow ups with an error message: ERROR: TypeError: callback is not a function

About

Avatar for user110429 @user110429 started