Every now and then I get problems sending code to the Espruino. What seems to happen, is I get errors as if I have been spelling function names incorrectly, there's always a letter or two missing.
The latest examples I have found is the following:
Does anyone have a clue why this keeps happening? There's nothing wrong with my code, it's just what gets returned after sending to the Espruino.
There were such issues a while ago - and you will find posts about it - where correct (and non-poking) code was running and doing that. In some instances it would just increase the byte / character value by some value, such as, "m" became "n", etc. If source code mutilation still happens, (most likely) the upload communication if faulty... and that can be many things.
For me it happened when something was running and making Espruino busy, and the upload did not stop it. Try pressing reset, reconnect, upload again. If this does not help, check your cable... also: what about your power: is something else - in addition to the board - supplied by the connected USB?
I mentioned non-poking code... I guess your code does not - literally or otherwise - poke around in the memory... ;-)
This looks like the missing characters thing.
I've noticed that if the Espruino has been doing other stuff, "send to espruino" can sometimes result in the Espruino not being ready to receive data in time. Doing a reset() first seems to prevent this.
Also, the flow control is generally a bit flaky. Sometimes I seem to have problems, and have never found clear pattern with why. You can turn on Throttle Send (under settings, communication) to deal with this once and for all, at the cost of slower sending.
Which board are you using? The normal Espruino one?
Sometimes this happens because the code you're sending takes a while to execute. For instance:
for (var i=0;i<10000;i++);
// Lots and lots of program code
// Lots and lots of program code
Will lose characters, because data is being sent but Espruino is too busy to consume it. It can also sometimes happen when loading modules as well. As @DrAzzy says, turning on 'throttling' should really help - but you might also be able to tweak your code so it doesn't do any calculations until the onInit function.
Annoyingly Chrome doesn't let me use XOn/XOff flow control for serial communications, so it's a bit hard to make sure the buffer doesn't fill up. Espruino tries its best to throttle the data coming down USB, but if it 'nacks' the USB packets for too long then the PC gives up sending that packet and you lose characters.
I'll be switching over to a newer USB implementation for Espruino in the next month or so, and hopefully after that I can make it emulate hardware flow control - which would be a massive help.
I'm using the standard v1.4 board, I'm not doing any fancy poking around.
One thing I should point out is my code is being sent over Bluetooth.
I've now got a Cordova app running which changes my LED strip from my phone using Bluetooth also.
I've noticed that if I call basic functions without parameters everything is fine. But If I add complex objects as parameters my app seems to fail, but I don't know how to debug this on my phone.
Could this be related to how the data is pushed over Bluetooth?
What I mean is when the app fails could it be similar to the missing characters when using the IDE because if I'm only calling a function name over Bluetooth it never fails, only when passing an object as a param, it fails intermittently.
Have you tried turning on 'throttling' in the IDE settings? You could also check the value of E.getErrorFlags() to see if the upload itself somehow overflowed Espruino's internal buffers.
When you're sending function calls over bluetooth, have you previously called echo(0)? You can also get a similar effect by sending character #16 at the beginning of a line.
If you've still got echo turned on, what happens is Espruino sends back the characters that you send it, plus =undefined\n or similar when the function is executed (it's even worse for multi-line stuff). So if you're sending 8 characters (eg foo(42)\n) as fast as you can at 9600 baud down Bluetooth, Espruino's trying to send foo(42)\n=undefined\n (also at 9600 baud) so quite quickly the output buffer gets full and it waits, and then the input buffer gets full and it drops characters.
There's also potentially an issue that if you're using a WS2811 LED strip, Espruino has to turn off interrupts so that it can reliably output the waveform that's required. That means that if you're sending a lot of data to a big strip, and sending data down bluetooth via serial, characters can get lost.
Best way to avoid that right now would be to make sure that the sender leaves a pause after sending the command, so Espruino has time to send the data to the WS2811s.
Hopefully at some point soon I'll switch to using DMA for the WS2811s, and when that happens I can leave interrupts on and the problem should go away.
Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.
For a full reference visit the Markdown syntax.
© Espruino, powered by microcosm.
Report a problem