• It's literally just the 'Web Bluetooth Dashboard' code you found with input fields added and ...setValue replaced with document.getElementById("mytextinput").v­alue = whatever_you_got; that I posted above:

    <html>
     <head>
      <title>Values as inputs</title>
     </head>
     <body>
      <script src="https://www.puck-js.com/puck.js"></script>
      <script>
      // Called when we get a line of data - updates the light color
      function onLine(line) {
        try {
          var j = JSON.parse(line);
          console.log("Received JSON: ",j);
          document.getElementById("light").value = j.light*100;
          document.getElementById("temp").value = j.temp;
          document.getElementById("bat").value = j.bat;
          // here's where you would put your data online if you wanted it
        } catch(e) {
          console.log("Received: ",line, e);
        }
      }
      var connection;
      function connectDevice() {
        Puck.connect(function(c) {
          if (!c) {
            alert("Couldn't connect!");
            return;
          }
          connection = c; 
          // remove modal window
          
          // Handle the data we get back, and call 'onLine'
          // whenever we get a line
          var buf = "";
          connection.on("data", function(d) {
            buf += d;
            var i = buf.indexOf("\n");
            while (i>=0) {
              onLine(buf.substr(0,i));
              buf = buf.substr(i+1);
              i = buf.indexOf("\n");
            }
          });
          // First, reset Puck.js
          connection.write("reset();\n", function() {
            // Wait for it to reset itself
            setTimeout(function() {
              // Now tell it to write data on the current light level to Bluetooth
              // every second. Also ensure that when disconnected, Puck.js
              // resets so the setInterval doesn't keep draining battery.
              connection.write("setInterval(function(){Bluetooth.println(JSON.stringify({light:Puck.light(), temp:E.getTemperature(), bat:Puck.getBatteryPercentage()}));},1000);NRF.on('disconnect', function() {reset()});\n",
                function() { console.log("Ready..."); });
              }, 1500);
            });
          });
    
      }
     
      </script>
      <h1>Your data</h1>
    
      <label for="light">Light</label> 
        <input name="light" id="light" type="text"><br/>
      <label for="temp">Temperature</label> 
        <input name="temp" id="temp" type="text"><br/>
      <label for="bat">Battery</label> 
        <input name="bat" id="bat" type="text"><br/>
      <button onclick="connectDevice()">Connect</button>
     </body>
    </html>
    
About

Avatar for Gordon @Gordon started