• The DISK_ERR issue itself is trivial to reproduce:

    var fs=0;
    function randint(max) { return Math.round(Math.random()*max); }
    
    
    
    function onInit() {
        digitalWrite(A14,1);
        setTimeout("doInit();",2000);
    }
    
    function doInit() {
        digitalWrite(A14,0);
        fs=require("fs")
        setInterval(function(){dologs();},10000)­;
    
    }
    
    function dologs() {
        digitalWrite(A15,1)
        var temp=randint(10);
        fs.appendFile("testlog.log","ASDF,"+temp­.toString()+",Time,"+getTime().toFixed()­+"\n");
        digitalWrite(A15,0)
    }
    
    onInit();
    

    This will run for a while, until eventually, every attempt to write results in DISK_ERR. This itself is a Bad Thing.

    However, it does not run out of memory!

    So why does it run out of memory when running the full setup?

    var g = 0;
    var d = 0;
    var inits=new Uint8Array([0,0,0,0]);
    var t=-1;
    var rh=-1;
    var t2=-1;
    var rh2=-1;
    var line1="";
    var line2="";
    var fs;
    var activepin="";
    
    
    function onInit() {
        digitalWrite(A14,1);
        digitalWrite(A13,1);
        setTimeout("doInit();",2000);
    }
    
    function doInit() {
        digitalWrite(A15,1);
        fs=require("fs")
        SPI3.setup({ baud: 1000000, sck:B3, mosi:B5 });
        digitalWrite(A13,0);
        g=require("PCD8544").connect(SPI3,B6,B7,­B4, function() {
            g.clear();
            g.drawString("LCD OK",0,0);
            g.drawLine(0,10,84,10);
            g.flip();
            digitalWrite(A15,0);
            setTimeout("inits[0]=1;endInit();",100);­
        });
        d=require("DHT11").connect(C10)
        d.read(function(a){ t=a.temp; rh=a.rh; inits[1]=1;endInit();});
        e=require("DHT22").connect(C11)
        setTimeout(function(){ e.read(function(a){ t2=a.temp; rh2=a.rh; inits[2]=1;endInit();});},2000);
    
    }
    
    function endInit() {
        if (inits[0]==1 && inits[1]==1 && inits[2]==1 && inits [3]==0) 
        {
            inits[3]=1;
            digitalWrite(A14,0);
            g.clear();
            g.drawString("Init OK!",0,0);
            g.flip();
            setInterval(function() {doMeasure();},5000);
            setTimeout(function(){setInterval(functi­on(){doMeasure2();},5000);},2500);
            setInterval(function(){dologs();},30000)­;
        }
    }
    
    function doMeasure() {
        d.read(function(a) {
            if (a.rh!=-1 && a.temp < 50) {
            	rh=a.rh;
            	t=a.temp;
            }
            updateLCD();
        });
    }
    
    function dologs() {
        fs.appendFile("timetemp.log","DHT11,"+t.­toString()+","+rh.toString()+",DHT22,"+t­2.toString()+","+rh2.toString()+",Time,"­+getTime().toFixed()+"\n");
    }
    
    function doMeasure2() {
        e.read(function(a) {
            if (a.rh!=-1 && a.temp < 50) {
                rh2=a.rh;
                t2=a.temp;
            } 
            updateLCD();
        });
    }
    
    function updateLCD() {
        g.clear();
        if (t!=-1) { 
            g.drawString("Temp: "+t.toString()+"C",0,0);
            g.drawString("RH: "+rh.toString()+"%",0,10);
            g.drawString("Temp: "+t2.toString()+"C",0,20);
            g.drawString("RH: "+rh2.toString()+"%",0,30);
        } else {
            g.drawString("DHT11 not",0,0);
            g.drawString("working!",0,10);
        }
        g.drawString(line1,0,20);
        g.drawString(line2,0,30);
        g.flip();
    }
    onInit();
    

    All I can think of is that this DISK_ERR disrupts other things happening at the same time, like DHT read or LCD update.

    Unfortunately, I've never been able to catch it between the first time it gives the DISK_ERR and when it runs out of memory, in order to see if it's leaking memory every time, or whether it survives until the error happens at a critical moment.

About

Avatar for DrAzzy @DrAzzy started