• The code I'm uploading. Basically, it allows me to connect my android app and retrieve log files.

    var currentLog = {};
    var log = {};
    
    function ut(epoch) {
      setTime(epoch);
    }
    
    function listFiles(f) {
      f = typeof f !== 'undefined' ? f : /.log$/;
      return require("Storage").list(f);
    }
    
    function eraseOldest(files) {
      require("Storage").erase(files[0]);
    }
    
    function eraseAllLogFiles(files) {
       console.log(files);
       for (i=0; i <= files.length; i++) {
         console.log("erasing "+files[i]);
         require("Storage").erase(files[i]);
       }
    
    }
    
    //Record sensor data and dump in file when buffer exceeds 96 entries for 24/hr
    function fillLog() {
      var data = Puck.capSense();
      var date = (new Date()).toISOString();
      //Write to RAM if less than
      if (Object.keys(currentLog).length < 5) {
        currentLog[date] = data;
      } else {
        var files = listFiles();
        //Check if storage is full, cleanup oldest
        if (files.length > 5) {
          //Deleteing files to write new
          eraseOldest(files);
        }
        //Wirite to file if log is full
        currentLog[date] = data;
        currentLog["lastdate"] = date;
        require("Storage").writeJSON(date + ".log", currentLog);
        currentLog = {};
      }
    }
    
    function getData(file) {
      if (file == "undefined") {
        return require("Storage").readJSON(listFiles()[0]);
      } else {
        return require("Storage").readJSON(file);
      }
    }
    
    //Sync data fromDate defines latest log files we want to receive
    function sd(fromDate) {
      var files = listFiles();
      for (i=0; i <= files.length; i++) {
        console.log("&&")
        var file = files[i];
        if (typeof file !== "undefined" && Date.parse(file.substr(0, file.indexOf("."))) > fromDate) {
          log = require("Storage").readJSON(file);
          console.log(log);
        } else if (typeof file == "undefined") {
          console.log("DONE")
          return;
        } else {
          console.log("No logs found for this date range");
        }
      }
    }
    
    function startMonitor() {
      //setTime(epoch);
      setInterval(fillLog, 2000);
    }
    
    // Change the name that's advertised
    NRF.setAdvertising({}, {name:"Test"});
    
    var Blink = function(times, frenquency)
    {
      for(var i = 0 ; i< times ; i++)
      {
        setTimeout(function() { LED1.write(true)}, frenquency*2*i+1);
        setTimeout(function() { LED1.write(false)}, frenquency*2*i+frenquency);
      }
    };
    
    NRF.on("connect", function(addr) {
      Blink(4,250);
      
    });
    
    NRF.on("disconnect", function(addr) {Blink(2,250);});
    
    //DELETE FOR PROD
    eraseAllLogFiles(listFiles());
    
    //MONITOR ON STARTUP
    startMonitor();
    
About

Avatar for user133430 @user133430 started