-
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
-
-
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 :(.
-
Bought this newish esp32 flavor, soala
https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/hw-reference/esp32s2/user-guide-saola-1-v1.2.htmlthe esptool can't upload the binary to flash apparently because the crystal frequency is different.
It seems this "new" frequency is not supported and/or the the esptool is not reading the correct value from the board. Has anyone else tried this board? Can the binary be recompiled to support this apparent hardware difference?Chip is unknown ESP32 (revision 1) Features: WiFi, Single Core, VRef calibration in efuse, Coding Scheme Repeat (UNSUPPORTED) WARNING: Detected crystal freq 344.33MHz is quite different to normalized freq 40MHz. Unsupported crystal in use? Crystal is 40MHz MAC: 3c:08:5b:80:ea:bd Uploading stub... Running stub... A fatal error occurred: Invalid head of packet (0x50)
I'm using this script which works fine with wroom and "regular" wrover.
#!/bin/bash VER=${1:-latest} esptool.py \ --port /dev/ttyUSB0 \ --baud 115200 \ --chip esp32 \ --after hard_reset write_flash \ -z \ --flash_mode dio \ --flash_freq 40m \ --flash_size detect \ 0x1000 ./$VER/bootloader.bin \ 0x8000 ./$VER/partitions_espruino.bin \ 0x10000 ./$VER/espruino_esp32.bin
-
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,tls,http,NetworkJS,Wifi,TelnetServer,crypto,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 >
-
yes there is a rollup plugin for typescript so would be easy to add this.
https://github.com/rollup/plugins/tree/master/packages/typescript
Not sure if reducing to es6 and then following with what I have done (buble, etc) is best or just tell it to go all the way to es5. The later would include many superfluous transformations and defeat what I was trying to do which was only transform what was needed with buble and that single async/await.
-
Using esp32 with latest dev V2.
After wifi connection I see this
WARNING: Wifi:startMDNS - espressif
But when I do a
mdns-scan
from my dev machine I do not see an expectedespressif.local
when it says
startMDNS
is it not announcing/responding?Further what is that state of the utility mDNS module (for scanning, and querying from the esp device) that I see here at this gist. What it added. I see no mDNS module listed.
https://github.com/espruino/Espruino/issues/1376#issuecomment-447653649 -
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 calledthis 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 aconsole.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);
-
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.
-
-
I've put together a rollup starter repo with buble transforms for features not supported currently plus one pretty simple babal plugin for just async/await. Should work on any device (if you change the npm scripts). The starter currently runs a set of extended feature examples as a "test". With more work this could be made into something more generic which would allow noobs to get going faster with less pain. It will pretty much allow me to use my existing code es6/esm without too much modification nor too much transpiled bloat.
It is structured so that a user works on
app.js
coding the app class therein for their particular application.Let me know if you successfully used it or what the issues are (can use github issue tracker). If the idea of a starter like this seems like a good idea then maybe others can help with improvements/upgrades.
-
In node/browser if I need to incorporate an event emitter I either use the native events module or third party. Typically I'd create a new class by extending the event emitter. Like so. https://nodejs.org/api/events.html
import EventEmitter from 'events' class SomeClass extends EventEmitter { constructor() { } }
but it seems that all (plain?) objects in Espruino have an event emitter baked in by default. https://www.espruino.com/Reference#l_Object_emit
So when I make a new class or make an object like so I get an event emitter as well?
Is the actual event emitter module available? If so where is that in the api docs
const obj = {} class SomeClass { constructor() { } } const cls = new SomeClass() obj.on('test', val => { console.log(val) }) cls.on('test', val => { console.log(val) }) cls.emit('test','class') obj.emit('test','object')
-
@fanoush thanks for the link. Surprisingly V2 seems to already support most of what I would need so maybe don't need to transpile or just use buble for the one off requirements like block scoping which I can't tell from table is supported. I will report back to this thread whatever I had to do and its impact.
-
I understand the limitations. Mostly just need to to spin up a TCP socket client or server and manipulate the gpio bus. Sockets are supported in Espruino with the very similar to Node net library. This will be a simple refactor of my es6+ code written for node 14 (as long as I can transpile). By using my json packet command library (via the socket) I can offload any web UI and most other computation to a much more capable machine.
Initially I figured on doing this all in CPP but the idea of basically have one code base for my json packet socket client/server is appealing. So even a little transpile bloat should be tolerable given I don't intend to run much code on esp32.
Mostly just need a few things like class syntax and promises/async/await (to avoid callbacks), arrow funcs, let/const/scope and a few of the native object improvements. Rollup already handles esm to cjs.
-
This library from espressif has a config method that accepts static ip as demonstrated in tutorial below.
Can this just be incorporated?
https://randomnerdtutorials.com/esp32-static-fixed-ip-address-arduino-ide/
Alternatively If I can't get to this I'll set up a fixed IP from my DHCP server based on MAC for now.
-
I want to write all my code in >ES6 (actually want to match what is implemented in Node 14 which is a good bit of ES8/2017 too). I am already using rollup but will need some transpilation. What is actually supported in Espruino 2.0+? I mean should I transpile/shim to ES5 or do I need to go older?
Maybe if I knew exactly what was supported I could use buble to only transpile what is needed as in a espruino column like in this chart showing what is implemented. https://kangax.github.io/compat-table/es6/
-
-
-
Seems the espruino tool doesn't have a way to start a terminal session in the same command right after an upload (and save)? so I've been running a second command right afterwards and that's what has been throwing the error whenever save is called
I did use the suggestions from the link you provided to that was helpful.
import {app} from './app.js' const PRODUCTION = false // this will be called on power up, if code was saved function onInit(){ setTimeout(app.call(null,opts),PRODUCTION?0:5000) // wait for possible terminal connect } setTimeout((PRODUCTION)?save:onInit,1000)
So I guess my question is how does one start a terminal session after upload (no save) in order to see the beginning stdout output. Alternatively I suppose I could send stdout tee'd to a file and view the file after connect (I have no clue how to do that on esp32)
I guess in general I'm used to my nodejs 14+ coding degugging/workflow under linux (i.e. full sbc running linux and nodejs) so I have some learning regards rolling up of es2017+ and then debugging and logging code on the esp32 device. Although the webide is fine I'm only interested in using my dev IDE's that being Atom and VsCode and writing in 2017+. That explains why I am using the cli directly.
Thx for you input @MaBe
-
-
no firmware that's fine. Just trying to upload code and get it to persist across boot (.i.e. move from ram to flash). That's a little sample code above that causes the error.
Actually any code will. The
save()
function I understand moves code from ram to flash so it persists across boots right? Whenever I appendsave()
I get this error.The error occurs when I use
save()
in the webide as well so looks like I am not grokking the purposesave()
since the webide allows one to upload to resettable flash how do I invoke that in the command line? -
Running esp32 wroom
trying to flash from the cli
results in this error and the code is not written to flash.--] Compacting Flash... --] ERROR: >> jshKickWatchDog Not implemented,using taskwatchdog from RTOS
code and cli command
console.log('program started') setInterval(function(){ console.log('lubdub') },3000) save()
espruino --port /dev/ttyUSB0 -b 115200 --no-ble --board ../boards/ESP32.json
I was able to flash from the webIDE so it must be something particular to my direct use of the cli.
I must be missing some setting?
Related: Maybe the json job file is the way to go so I can set config details other than from "switches. Does the job file merge with defaults so I can just set those I need or do I have to set all values if I use it. Can I still use command line switches with a job file? ex. the --board switch as it seems the config for board only takes a url not a local path.
-
running esp32 wroom with
#!/bin/bash espruino \ -v \ --port /dev/ttyUSB0 \ -b 115200 \ --board boards/ESP32.json \ $1
where $1 is the code file I am uploading.
I get this in terminal output but it still connects so maybe the Noble:getPorts is not required if I explicitly supply a port. If so can I disable it so it doesn't have to wait for 10 sec timeout EVERY time I upload code.
I assume this is some auto port finder that isn't working for me.
Noble: getPorts - not initialised Noble: Didn't initialise in 10 seconds, disabling. Connected Ok Connected
-
@gordon that was an excellent reply, exactly what I needed to know. This information should be in some form in their FAQ/Docs/Wiki since more than likely an Espruino adopter would be coming from coding nodejs. It's absence prompted me to use the forum. (espruino folks listening here?)
So summarizing your post
I should expect to just write code that calls the API mostly. There is a package manager and module system (still commonjs?) but use it sparingly if at all. Don't count on using any package from NPM unless it has very few or no dependencies. At least for now there is limited ES6.
Actually being an ole geezer I can remember the good old days of the first IBM PCs and trying to get your (FORTRAN/BASIC) program to fit into 128K. It's back to the future..fun
@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.