Skip to content

slowWrite is automagically configured, and is not logged even with -v verbose flag and the default is true #178

@fanoush

Description

@fanoush

Was trying to figure out why uploading file to storage takes many minutes and had finally look into source.

espruino --help, espruino --listconfigs has no hint there is something like slowWrite flag
-v logs a lot of stuff including data that is going to be sent but again nothing that would hint what happens while the data is transferred

Finally I had to find and uncomment this line

//console.log("Sending block "+JSON.stringify(d)+", wait "+split.delay+"ms");
to see what happens.

Sending block "\u0010print()\n\u0010require(\"", wait 50ms
Sending block "Storage\").write(\"ba", wait 50ms
--]
Sending block "ck-sb.JPG\",atob(\"/9", wait 50ms
Sending block "j/4AAQSkZJRgABAQEAY", wait 50ms
Sending block "ABgAAD/4RCIRXhpZgAA", wait 50ms
Sending block "TU0AKgAAAAgABAE7AAI", wait 50ms
Sending block "AAAAHAAAISodpAAQAAA", wait 50ms
Sending block "ABAAAIUpydAAEAAAAOA", wait 50ms
Sending block "AAQcuocAAcAAAgMAAAA", wait 50ms
....

Maybe this line could be enabled with "-v"?

Some magic is here

if (vCurrent > 1.43 &&
(env.CONSOLE=="USB"||env.CONSOLE=="Bluetooth"||env.CONSOLE=="Telnet")) {
console.log("Firmware >1.43 supports faster writes over USB");
Espruino.Core.Serial.setSlowWrite(false);
} else if (vCurrent >= 2.18 && env.BOARD=="ESP32" && env.CONSOLE=="Serial1") {
console.log("Firmware >=2.18 on ESP32 supports flow control");
Espruino.Core.Serial.setSlowWrite(true);
}
but in my case nothing matched so the default of true
var slowWrite = true;

was silently used with no logging. BTW why the ESP32 message says it uses flow control and then slow writes are set to true, shouldn't it be false because flow control works and can stop the flow?

I was actually using -p tcp://127.0.0.1:2222 so also the driver in
https://github.com/espruino/EspruinoTools/blob/8eb606cff5992a64c3127b8bf32fd0b01ad7873c/core/serial_node_socket.js
has no workaround like e.g. this

Espruino.Core.Serial.setSlowWrite(false, true); // hack - leave throttling up to this implementation

more places https://github.com/search?q=repo%3Aespruino%2FEspruinoTools%20setSlowWrite&type=code

And looks like the versionChecker.js is parsing console name from process.env (USB, Telnet, ...) instead of setting it from the real transport that is used. So in my case I was using TCP port but my console was not named "Telnet". I am not sure adding "SWDCON" next to "Telnet" is good workaround.

Another puzzling thing was that I found this code

split = findSplitIdx(split, /\x03/, 250, "Ctrl-C"); // Ctrl-C
split = findSplitIdx(split, /reset\(\);\n/, 250, "reset()"); // Reset
split = findSplitIdx(split, /load\(\);\n/, 250, "load()"); // Load
split = findSplitIdx(split, /Modules.addCached\("[^\n]*"\);\n/, 250, "Modules.addCached"); // Adding a module
split = findSplitIdx(split, /\x10require\("Storage"\).write\([^\n]*\);\n/, 500, "Storage.write"); // Write chunk of data

that contains matches for Storage.write with some 500ms delays but it does not match because default is "--config STORE_LINE_NUMBERS=true" and there is extra stuff after "x10" with line number - like u0010\u001b[10drequire(\"Storage\").write. When fixed it does not match anyway (maybe because of
if (!sendingBinary) {
)

Some suggestions to improve this:

Can the slowWrite be false by default?
If not can the serial_node_socket set it to false like in other place and Telnet is removed from the check?
Can the slowWrite flag be overriden from command line or --config parameter so it is more visible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions