Avatar for user117036

user117036

Member since Aug 2020 • Last active Jul 2022
  • 0 conversations
  • 2 comments

Most recent activity

  • in Projects
    Avatar for user117036

    You beat me to it. I was excited because a friend already pointed me in the right direction and I got it working earlier today. Thanks for the quick response and I still am looking forward to looking over the example you shared. Here is the code I used

    
    <html>
     <head>
       <meta name="viewport" content="width=640, initial-scale=1">
     </head>
     <body>
       <link href="/static/css/tinydash.css" rel="stylesheet">
       <script src="/static/tinydash.js"></script>
       <script src="/static/puck.js"></script>
       <script>
    var t;
    var j_light;
    t = [];
      function onLine(line) {
        try {
        
      
          var j = JSON.parse(line);
          console.log("Received JSON: ",j);
          j_light = j.light*100;
          t.push(j_light);
          elements.light.setValue(j_light);
          elements.logg.log(j_light);
          elements.gr.setData(t);
        
        } catch(e) {
          console.log("Received: ",line);
        }
      }
      var connection;
      function connectDevice() {
        Puck.connect(function(c) {
          if (!c) {
            alert("Couldn't connect!");
            return;
          }
          connection = c;
          // remove modal window
          elements.modal.remove();
          // Handle the data we get back, and call 'onLine'
          // whenever we get a line
          var buf = "";
          connection.on("data", function(d) {
            elements.log.log(40*Math.sin(Date.now()/­1000)+50);        
            //elements.logg.log(connection.write("di­gitalRead(BTN);\n")); 
            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
              // 10 times a second. Also ensure that when disconnected, Puck.js
              // resets so the setInterval doesn't keep draining battery.
              //TD.update({log : 40*Math.sin(Date.now()/1000)+50});
              connection.write("setInterval(function()­{Bluetooth.println(JSON.stringify({light­:Puck.light()}));},100);NRF.on('disconne­ct', function() {reset()});\n",
                function() { console.log("Ready..."); });
              }, 1500);
            });
          });
      }  
      //function getTempValue() {
       // for (var i=0;i<100;i++) t.push(i);
        //connection.write("Puck.temp();\n", function(temper){
        //for (var i=0; i<100;i++) t.push(temper);
          //    {elements.gr.setData(t);}
         //  setTimeout(function() {
          // getTempValue();     
       //  }, 250);
      //  });
     // }
    
      // Set up the controls we see on the screen    
      var elements = {
        heading : TD.label({x:10,y:10,width:200,height:50,­label:"My Dashboard"}),
        b:TD.button({x:10,y:290,width:200,height­:100,label:"Press Me",value:0,name:"button",onchange:funct­ion(e){elements.log.log("Pressed!");}}),­
        log:TD.log({x:430,y:10,width:190,height:­200,label:"A Log",text:"A\nB\nC"}),
        logg:TD.log({x:630,y:10,width:190,height­:200,label:"A Log",text:"A\nB\nC"}),
        //function() {
          //  connection.write("Puck.getBatteryPercent­age();\n");
        //elements.logg.log(connection.write("Pu­ck.getBatteryPercentage();\n"));
        //Puck.eval("{bat:Puck.getBatteryPercent­age()}"
      //  }}),
        light : TD.gauge({x:10,y:70,width:200,height:220­,label:"Light",value:0,min:0,max:100}),
        redled : TD.toggle({x:210,y:200,width:200,height:­90,label:"Red LED",value:0,onchange:function(el,v) {
          connection.write("LED1.write("+v+");\n")­;
        }}),
       flash : TD.button({x:420,y:200,width:190,height:­90,label:"Flash!",value:0,onchange:funct­ion() { 
          connection.write("digitalPulse(LED3, 1, 500);\n");
        }}),
        vs:TD.value({x:10,y:400,width:200,height­:60,label:"Steppable Value",value:"1.2",min:1,step:0.1,max:2}­),
       // gr:TD.graph({x:220,y:420,width:400,heigh­t:170,label:"A Graph",data:function(){
      //  connection.write("Puck.temp();\n");}}),
        gr:TD.graph({x:220,y:420,width:400,heigh­t:170,label:"A Graph",data:t}),
        modal: TD.modal({x:10,y:10,width:190,height:430­,label:"Click to connect",onchange:connectDevice})
      }
      
      elements.log.log("Hello");
         for (var i in elements) document.body.appendChild(elements[i]);
         
      </script>
     </body>
    </html>
    
    
  • in Projects
    Avatar for user117036

    I am trying to get the graph to work with realtime data using the tinydash widget. The graph in the example file works but it is just plotting a curve on start without any updates. Whenever I try to push live sensor values to the graph I get no line being drawn. Is it possible to get an example of the tinydash graph widget that updates with new incoming values. Thanks

Actions