• require("IRReceiver").connect(NodeMCU.D1, function(code) {
      console.log(code);
      if ( code.length >= 33 ) {
        var l=parseInt(code.slice(1,16),2);
        if ( l === 15344 ) {
            lcd.setCursor(0,1);
          var k=parseInt(code.slice(17,21),2);
          console.log({k:k,b:button[k]});
          lcd.clear();
          lcd.print(button[k]);
        }
      }
    });
    

    I have discovered at night a fluro lamp triggers the IR reciever. These random pulses after a couple of hours trigger this:

    11111111111111111111111111111111111111111111111111111111111101111111111110111
    11111111111111111110111111111111111111111110
    1111111111111111111111111111111111111111111110111111111111111111101111
    11111111111111111111111111111111011111111111
    0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101111111111111111111111111111111111111110111111111111110111101111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111
    11111111111111111111110111011111111111111111111111111111111111111111110111111111111111111111111111110111111111111111111111111101111111111111111111110111111111111111111111111011111111111111111111111011111111111111111110111111111111111111111111111111111111111111111101010111111111111111111111111111111111111111111111110111011111111111111111111111111111111111101111111111111111111101101111111011111111111111111011111111111111111101111111111111111111111111111111111111111011111111111101011111111111111111111111
    ERROR: Out of Memory!
    ERROR: Ctrl-C while processing watch - removing it.
    Execution Interrupted during event processing.
    at line 1 col 40
    ...astTime;b&&(clearTimeout(b),b=void 0);.04<c?(""!==a&&e(a),a=...
                                  ^
    in function called from system
    > 
    

    it appears to be in this block:

     // set our callback to happen whenever pin goes low (eg, whenever pulse starts)
      setWatch(function(e) {
        var d = e.time-e.lastTime;
        if (timeout) {
          clearTimeout(timeout);
          timeout = undefined;
        }
    

    I believe the cause is here:

        if (d>0.04) { // a gap between transmissions
          if (code!=="") callback(code);
          code = "";
        } else {
          code += 0|d>0.0008;
    

    So code just keeps getting longer.... I wondering what the best way is to make this robust?

    Set a watch dog timer that truncates the code string if it gets too long, or simply controls it's length?

    http://www.espruino.com/modules/IRReceiver.js

About

Avatar for Wilberforce @Wilberforce started