• Hey guys,

    I have an Espruino WiFi (love this thing) with an 8x8 matrix led display as recommended here. I have node-red running on my Raspberry PI 4. My Espruino makes calls every 3 seconds to my PI to get the current time and displays it scrolling across the matrix.

    The problem is it just stops after about 10 minutes, I checked the Rasperry Pi and it is still being called by the Espruino every 3 seconds in the log. So the reason it's not displaying could be in this script somewhere, just not sure how to even debug it...

    var WIFI_NAME = "BTHub-XXX";
    var WIFI_OPTIONS = { password : "XxXxX" };
    var http = require("http");
    
    var output = 'default text';
    var interval = false;
    
    const ANODES = [B6,A7,A6,B9,A4,B8,B4,B3];
    const CATHODES = [B0,B5,A0,B7,B10,A1,B1,A5];
    var g = Graphics.createArrayBuffer(8,8,1);
    
    var wifi = require("Wifi");
    
    function onInit() {
      wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
        if (err) {
          console.log("Connection error: "+err);
          return;
        }
        console.log("Connected!");
        getData();
        start();
        scroll();
      }.bind(this));
    }
    
    
    // Start scanning out the LED display
    function start() {
      console.log('start');
      var b = new Uint8Array(g.buffer);
      // Pre-bind digitalWrites to make things faster
      var a = digitalWrite.bind(undefined,ANODES);
      var c = digitalWrite.bind(undefined,CATHODES.con­cat(ANODES));
      return setInterval(function() {
        b.map((d,i)=>{c(65280^(256<<i));a(d);});­c(65280);
      },10); // 100 Hz
    }
    
    function scroll() {
      var i = 8;
      if (interval)
        clearInterval(interval);
      
      interval = setInterval(function(){
        if(i == -(output.length * 4)) i = 8;
        g.clear();
        g.drawString(output, i, 2);
        i--;
      }, 100);
    }
    
    function getData() {
      setInterval(function(){
        http.get("http://192.168.1.146:1880/hell­o-data", function(res) {
          res.on('data', function(data) {
            output = data;
            console.log(output);
          }.bind(this));
        });
      }.bind(this), 3000);
    }
    
  • Wed 2019.11.27

    Hi @Coder2012, don't have these devices to be able to test,

    'just not sure how to even debug it'

    but I did notice a few things. It's likely bad data is being passed to the graphics object, or an array is going out of range or running out of memory perhaps.

    Function scroll() is called one time. L42 and L43 will only be called one time, incidentally
    setInterval() returns a number, the timer ID, not a boolean, so var interval is never cleared.

    http://www.espruino.com/Reference#l__glo­bal_setInterval



    As L45 is being called ten times a second, to check if running out of memory, place a
    process.memory() inside that interval. I'd also only check, say every tenth time using a conditional such as if( (skipcounts % 10) == 0 ) so that output to the console (Left-Hand side) may keep up. Could also check the arguments at that point to see if out of bounds errors may be occurring.

    http://www.espruino.com/Reference#proces­s



    Try placing a try/catch block around the functions called inside onInit() to see if any errors are occurring, bubbling up and not being caught.


    Suspect L34. Using concat repetitively may be appending beyond the available buffer size.

About

Avatar for Coder2012 @Coder2012 started