Program too big?

Posted on
  • First day with the Esrpuino Wifi. I'm not sure what to expect, and I realize that it's an embedded platform. I have a lot of experience with Arduinos, the Esquilo, etc.

    The following code will load and run if I comment out either the "startServer" or the "startLogging" functions. But if I try to run the whole program it fails with the following:

    >  1v95 Copyright 2017 G.Williams
    > >
    > =undefined Erasing Flash... Writing....................... Compressed 114368 bytes to 21007 Checking... Done! Running onInit()...
    > >ERROR: Prompt not detected - upload failed. Trying to recover... ERROR: Error processing Serial data handler - removing it. Execution
    > Interrupted during event processing. New interpreter error: CALLBACK
    > New interpreter error: BUFFER_FULL
    > >echo(1)
    > =undefined
    
    var WIFI_NAME = "oddballpeak";
    var WIFI_OPTIONS = { password : "mule$bacon44" };
    
    var wifi;
    var now = null;
    var sample_array = [];
    var arr_ptr = 0;
    var tempF = 32;
    var sampleCnt = 0;
    var date = new Date();
    var maxSamples = 672;
    var ow = new OneWire(B0);
    var sampleSec = 900;
    var http = require("http");
    
    function onInit() {
      wifi = require("EspruinoWiFi");
      wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
        if (err) {
          console.log("Connection error: "+err);
          return;
        }
        console.log("Connected!");
        initProcess();
      });
    }
    
    function initProcess() {
      http.get("http://www.pur3.co.uk/hello.tx­t", function(res) {
        now = res.headers.Date;
        epoch = Date.parse(now);
        setTime(epoch/1000);
        console.log("Now: ", date.toString());
        setTimeout(startLogging, 3000);
        setTimeout(startServer, 5000);
      });
    }
    
    function startServer() {
      http.createServer(function (req, res) {
        res.writeHead(200, {'Content-Type': 'text/html'});
        page = "<h3>Logging</h3><br>";
        for (var i in sample_array) {
            page += sample_array[i].ts;
            page += "\t";
            page += sample_array[i].degF;
        }
        res.write(page);
      }).listen(80);   
    }
    
    function startLogging() {
      var sensor = require("DS18B20").connect(ow);
      setInterval(function() {
        sensor.getTemp(function (temp) {
          now = Date.now() / 1000;
          floor = parseInt(now);
          mod = floor % sampleSec;
          if (!mod) {
            tempF = ((temp * 9) / 5) + 32;
            sample_array[sampleCnt] = { "ts" : floor, "degF" : tempF };
            if (++sampleCnt == maxSamples) {
              sampleCnt = 0;
            }
          }
        });
      }, 1000);    
    }
    
    save();
    
  • If I change the settings to minify it offline it loads perfectly. However, it's a little bit frustrating because it's apparently not the code itself that has a problem, which makes it pretty hard to understand and debug.

  • It's a little frustrating, because I can't really tell if I am doing something wrong and what I can do to mitigate the issues.

    There were no changes to settings or the program and I wasn't able to do anything with it this morning. This fragility with the interaction between the IDE and the device makes the IDE difficult to work with. I understand the complications of creating a device like this, and I would really like some insight into what is going on when I execute an upload/flash:

     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v95 Copyright 2017 G.Williams
    >
    =undefined
    Erasing Flash...
    Writing......................
    Compressed 114368 bytes to 20259
    Checking...
    Done!
    Running onInit()...
    ERROR: Prompt not detected - upload failed. Trying to recover...
    in function "registerLine" called from line 1 col 246
    ....registerLine("4,CONNECT",h),c.regist­erLine("0,CLOSED",k),c....
                                  ^
    in function "registerLine" called from line 1 col 275
    ...c.registerLine("0,CLOSED",k),c.regist­erLine("1,CLOSED",k),c....
                                  ^
    in function "registerLine" called from line 1 col 304
    ...c.registerLine("1,CLOSED",k),c.regist­erLine("2,CLOSED",k),c....
                                  ^
    in function "registerLine" called from line 1 col 333
    ...c.registerLine("2,CLOSED",k),c.regist­erLine("3,CLOSED",k),c....
                                  ^
    in function "registerLine" called from line 1 col 362
    ...c.registerLine("3,CLOSED",k),c.regist­erLine("4,CLOSED",k),ex...
                                  ^
    in function "registerLine" called from line 1 col 391
    ...c.registerLine("4,CLOSED",k),exports.­at=c,require("NetworkJS...
                                  ^
    in function "cmd" called from line 2 col 300
    ...ter AT+RST");else return l}),digitalWrite(x,1),digitalWrite(...
                                  ^
    in function "p" called from line 2 col 241
    ...")):setTimeout(d,0,null)})})
                                  ^
    in function "connect" called from line 1 col 169
    ...onnected!'),initProcess();});
                                  ^
    in function called from system
    ERROR: Error processing Serial data handler - removing it.
    Execution Interrupted during event processing.
    New interpreter error: CALLBACK
    >echo(1)
    =undefined
    New interpreter error: BUFFER_FULL
    

    Then I turn minification off (couldn't do anything without turning it on yesterday) and it loads the program, although it gives an error, so the behavior is very inconsistent:

     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v95 Copyright 2017 G.Williams
    >
    =undefined
    Erasing Flash...
    Writing........................
    Compressed 114368 bytes to 21752
    Checking...ERROR: Prompt not detected - upload failed. Trying to recover...
    Done!
    Running onInit()...
    >echo(1)
    =undefined
    Connected!
    Init:  Wed, 27 Dec 2017 13:51:06 GMT
    Starting logging
    Starting server
    
  • Take the save() out of the code you upload and type save on the left of the ide.

    Every time the device restarts the last thing it does is try to save sgain.

  • @Wilberforce Thank you. I think I got that from an example somewhere.

  • Great - glad you got this sorted! Do you remember where that example was? If it's on the Espruino site I might be able to change it.

    Sadly, as with most things, there's a lot of bad advice on the internet that I have no control over.

    This kind of thing has been happening a lot recently, so I guess about the only thing I could do is to add code to the Web IDE to detect when people do this and them warn them.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Program too big?

Posted by Avatar for user84292 @user84292

Actions