• Running an esp32 wroom with latest firmware. I am using the cli not the webide.

    I seem be running into an issue that involves my ignorance of how the espurino firmware manages the running js script process.

    I've been uploading my code via the cli and just assumed that there can be only one js process running at a time so after upload I assumed that the current running js scripts is killed and the newly uploaded one is started. That doesn't seem to be the case (e.g. all the callbacks for the newly upload code are never called). Note: when programming with arduino or espessif firmware/framework via platformio when I upload a new ccp program the old one is killed.

    So I tried to first upload a simple reset() script which supposedly purges the script in RAM then upload my code, nope that doesn't work either.

    So then I wiped the flash by uploading reset(true). Then I did a hard reset (button of esp dev board) so I know (via terminal) no script is running then upload my code and it works fine.

    So now I am forced to press the hard reset every time before uploading a new version of my code to RAM (during development). BTW if I then save code to flash and press hard reset it runs fine each time (because there was no already running js script).

    Thus it seems the former js code is still running even after a new upload, even after a soft reset?? Many times when programming in node the node process doesn't get killed (with cntrl-c) when script is exited and either have to include some shutdown code when SIGTERM is called (like stopping listeners) or I have to use the linux 'kill' command but. There is no process 'kill' nor linux SIGTERM for the esp32 (i.e. via espurino 'os') as far as I know

    So how does one manage (kill) the running js script during development? I suppose I just need a better explanation about how the espruino firmware manages RAM and running the running js process(es ?) therein. I just assumed given the limited resources that only one js script process at a time can be run.

  • reset(1) should erase all saved code and kill all running code as well. The only thing that stays the same should be wifi connection status.
    Can you create a minimal repro that shows this behaviour?

  • Although I am using the cli with rollup if I use the webide with this code below I get the same issue (callbacks are never called) even with "reset before send" in the IDE set.

    If I send

    reset(1)  // reset ram, clear flash
    require('Wifi').save('clear') // clear wifi credentials
    console.log('RAM,flash, and wifi settings have been cleared')
    

    separately before uploading same issue, no callbacks called.

    if I press my hard reset button on esp board then send/upload callbacks are called.
    if I then send/upload the same program then the callbacks are not called

    this behavior is totally consistent. That soft reset(1) never fixes the issue which I assume is that the previous code is running or for whatever reason no callbacks are called.
    I put in a console.log('udpdated code 2'); // increment for each send and I can see each upload that the just sent update is running but the callbacks never get called until I first do a hard reset.

    So what about my question can the firmware be running multiple scripts? or otherwise what would be causing the callbacks to be silent until a hard reset?? I have not investigated further because as I said unlike linux I just don't understand how espruino firmware manages memory and js processes.

    var wifi = require('Wifi');
    
    var data = { wifi:{ ssid:'zoesplace',
      password:'PalDgk19591960',
      hostname:'esp32test',
      'static':{ ip:'10.0.0.45',
        netmask:'255.255.255.0',
        gw:'10.0.0.1' } } };
    
      function connect(opts) {
    
        wifi.on('connected', () => {
          console.log('ESP connected to AP');
          console.log('udpdated code 2'); // increment for each send
           wifi.ping('10.0.0.1',function (res) {console.log('in ping callback', res.respTime,'ms');});
           setTimeout(function (val) {console.log('test timeout done');},5000);
        });
    
        wifi.on('disconnected', () => {
          console.log('ESP disconnected from AP');
        });
    
        var state = wifi.getStatus();
        console.log('determining wifi status');
    
        if (state.ssid === opts.ssid & state.station === 'connected') {
          console.log('already connected to', state.ssid);
          wifi.emit('connected');
        } else {
          console.log('not connected...connecting');
          wifi.connect(opts.ssid, {
            password: opts.password
          }, function (err) {
            console.log('in connect callback');
            if (err) { console.log('wifi connection error', err);}
          });
        }
        }
       
    connect(data.wifi);
    
  • Wait a moment, IIRC ESP32/8266 connect to Wifi automatically, if wifi credentials were saved. And IIRC reset() will not disconnect from wifi, just resets Espruino interpreter. So yes, your wifi.on('connected' will not fire, because it's already connected to wifi by the time your code is executed.
    So what I did is check in my startup code if it's connected to wifi. If not, than start connecting. If already connected, just run wifi releated startup code immediately.

  • just o to add - to do full soft reset there is E.reboot(), reset() just reinitializes the javascript interpreter, clears variables etc. The idea of reset() is that it restarts without closing console connection over bluetooth/wifi.

  • I noticed on ESP32, that sometimes a wifi.restore() is helpfull.

  • I'm beginning to suspect that is the esp wroom. It only has 512K RAM.

    I changed the code above to do 3 manual manual disconnects and you can see (below) both the disconnect and connect callbacks were called the first time but then not called afterwards (I used a timeout) even though it was really disconnected and connected. Sometimes though when I run it they may get all called for all three trials. The callback failure is not particularly consistent unless I fail to do a hard reset in which case then never get called.

    I know that for low.js the minimum requirement is wrover (has extra (ps)ram and flash) maybe that is also true for espruino? @MaBe? Have others had similar issues issues using a wroom??

    Explicit board JSON supplied: "../boards/ESP32.json"
    Connecting to '/dev/ttyUSB0'
    Connected
    environment { 
      "VERSION": "2v06.122", 
      "GIT_COMMIT": "eca6aae8", 
      "BOARD": "ESP32", 
      "FLASH": 0, "STORAGE": 262144, "RAM": 524288, 
      "SERIAL": "246f2855-5a80", 
      "CONSOLE": "Serial1", 
      "MODULES": "Flash,Storage,heatshrink,fs,net,dgram,t­ls,http,NetworkJS,Wifi,TelnetServer,cryp­to,neopixel", 
      "EXPTR": 1073484860, "PRODUCTION": false }
    determining wifi status
    not connected...connecting
    ERROR: Wifi: event_handler STA_START: esp_wifi_connect: 12298(SSID is invalid)
    WARNING: Wifi:startMDNS - espressif
    wifi connect callback
    ESP connected to AP
    application online at 10.0.0.225
    ---------------- manually disconnect/reconnect test -------------- 1
    forcing disconnect now
    wifi disconnect callback
    ESP disconnected from AP
    attempting reconnect in 5
    application offline
    determining wifi status
    not connected...connecting
    WARNING: Wifi:startMDNS - espressif
    WARNING: Wifi:stopMDNS
    wifi connect callback
    ESP connected to AP
    application online at 10.0.0.225
    ---------------- manually disconnect/reconnect test -------------- 2
    forcing disconnect now
    disconnect timeout
    disconnect callback failed but device is disconnected!!!
    ESP disconnected from AP
    attempting reconnect in 5
    application offline
    determining wifi status
    not connected...connecting
    true timed out trying to connect
    connect callback failed but device is connected!!!
    ESP connected to AP
    application online at 10.0.0.225
    ---------------- manually disconnect/reconnect test -------------- 3
    forcing disconnect now
    disconnect timeout
    disconnect callback failed but device is disconnected!!!
    ESP disconnected from AP
    attempting reconnect in 5
    application offline
    determining wifi status
    not connected...connecting
    true timed out trying to connect
    connect callback failed but device is connected!!!
    ESP connected to AP
    application online at 10.0.0.225
    done disconnect trial of 3 times
    >
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

uploading new js script doesn't kill current running script in RAM. - callbacks not called even if function completes

Posted by Avatar for dgk @dgk

Actions