uploading new js script doesn't kill current running script in RAM. - callbacks not called even if function completes #7416
Replies: 1 comment
-
Posted at 2020-09-08 by AkosLukacs
Posted at 2020-09-09 by dgk 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
separately before uploading same issue, no callbacks called. if I press my hard reset button on esp board then send/upload callbacks are 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. 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.
Posted at 2020-09-12 by AkosLukacs Wait a moment, IIRC ESP32/8266 connect to Wifi automatically, if wifi credentials were saved. And IIRC Posted at 2020-09-12 by @fanoush 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. Posted at 2020-09-12 by @MaBecker I noticed on ESP32, that sometimes a wifi.restore() is helpfull. Posted at 2020-09-14 by dgk 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? @MaBecker? Have others had similar issues issues using a wroom??
Posted at 2020-09-22 by dgk Well I bought a wrover and tried my code and this issue persists. Since my code looks "fine" I can only assume this is a bug in espruino. Looks like since the esp32 is not an official board so this bug may not be addressed. I was hoping to use espruino on an esp32 (even written a starter repo using rollup) and I'd like to make a donation but it's a catch22. I'd like to donate but only if it can be used. If I can't get a simple program running with stable behavior (callbacks called dependably) well then it's not useful :(. Posted at 2020-09-22 by @MaBecker
but you can file a issue for this at https://github.com/espruino/Espruino/issues Posted at 2020-09-22 by parasquid
The firmware doesn't run multiple scripts; there is just one forever loop running and when you "upload" you execute the code you are uploading line by line, as if you typed them in the left hand side (except for things like modules and inline c/asm which are preprocessed or minified by the web ide then uploaded). Like everyone said, reset should have fixed this but maybe it is a bug in the ESP32 port? If it's just a matter of resetting, you can always wire up something to the reset pin and trigger that through software when you want to reset. This would make you lose connection, but then again when your project is deployed you don't always need to be connected. Posted at 2020-09-23 by dgk this is more than just resetting. I reset and upload/run my script and initially the callbacks are called but then fail per the output I supplied. Why would it initially call a callback but on the second call of the function fail to call the passed callback even though the function has clearly completed its task (e.g. disconnect). That seems like a bug to me (coming from nodejs world that has never happened to me) although I'm still a noob when it comes to javascript/espruino on esp32 Posted at 2020-09-23 by parasquid Not sure if this would work but can you try putting the Actually nvm, consider me confused which callback you're referring to :D I saw an I personally just do simple things like the ones found here: https://www.espruino.com/ESP32#connecting-to-wifi Maybe try this one first and see if the Posted at 2020-09-23 by parasquid I just flashed an ESP32 I have with 2.07 and uploaded this code:
I then setup a hotspot on my phone to control the wifi connection and disconnection outside of the ESP32. The callbacks are running, but it looks like the issue is that disconnect status isn't immediately detected. I can force the detection of the disconnect (and the callback) by doing something on the network (like getting a url)
Sometimes though, disconnection is immediately detected and the callback runs (again tested by turning on or off the hotspot on my phone). And if you wait long enough, the ESP32 detects the disconnection and then runs the callback. So maybe the best solution for now is to have a Posted at 2020-09-23 by parasquid Just to add, connecting and disconnecting the hotspot in quick succession will sometims leave the wifi status as
Posted at 2020-09-23 by parasquid Manually calling
Posted at 2020-09-23 by dgk @parasquid this "no callback" issue wasn't restricted to the connect and disconnect functions it was doing the same for wifi.ping, likely any callback. The code I posted at the top was not the same code that generated the output above . The code whose output is above is from my starter repo that uses rollup and the listeners are not in the connect function. So rather than try to post all the pieces here is the link. I just committed the version of the "app.js" that does the three trials. https://github.com/dkebler/espruino-starter.git You'd be able to clone it and try my actual code. Directions are in the readme. It's swift to get this running. Maybe running the exact same code we can track down my issue. In my wifi class there is a getter for a complete status which can be used at any time to see what state/status the wifi is in. I'll check again but I don't recall the disconnect being left in station: "AUTH_LEAVE" when the the callback was never called. one thing to note is that station might be "connected but the ssid is empty which is really a disconnected state (as I can't ping the esp like this). That's why my connected getter checks both station and ssid. Posted at 2020-09-23 by @MaBecker check this test code that was used to verify the functionality of wifi events https://github.com/espruino/Espruino/blob/master/targets/esp32/tests/wifiEvents.js |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-09-08 by dgk
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.
Beta Was this translation helpful? Give feedback.
All reactions