Memory efficient way of taking in data from an http request that needs to be written to EEPROM? #681
Replies: 5 comments
-
Posted at 2017-01-11 by @gfwilliams Actually there's no need to eval/stringify it at all.
Then to decode, call You might be able to do a little better (avoiding the new allocation for toUint8Array) but hopefully that'll be good enough for you. If you do it right you can make sure that |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-13 by DrAzzy Thanks! That's the kind of thing I was hoping for - I'll try it and see how I get on with it. Also, I'm just staring at that String.fromCharCode.apply(null,data) line... I do not understand why this works the way it does, or frankly how apply is supposed to work with return values at all (none of the js docs I've looked at seem to describe how apply() deals with the fact that he's got N return values to return, but can only return one thing - it seems like at least in the case of strings, they get concatenated, but I'd love to find real docs that describe this). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-16 by @gfwilliams
It's actually pretty horrible to do in Espruino since it ends up creating a sparse array for all the arguments, but on the desktop it's a really handy shortcut ;) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-17 by DrAzzy The code to generate the string is generated on the Espruino too - an import and an export function. But it does seem to work:
Thanks! And yeah, I was getting it confused with .map(), and had forgotten you could pass multiple arguments to String.fromCharCode(). Been writing too much C lately. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-01-17 by @gfwilliams :) There's a function called |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2017-01-11 by DrAzzy
I'm working on a project with Espruino on ESP8266 (I'm going to have like 7 of them - these are pingpong light controllers; I finally got back into that one. This is for importing/exporting patterns), where data is stored on an EEPROM.
I need some way to receive data via url parameter, then convert that into a Uint8 array or something else I can write to the EEPROM. The size of the data is 128 bytes.
My original plan was to use JSON.stringify and base64 encode that, then send that to the Esp8266-running-Espruino as a parameter. Then it would base64 decode it, eval it, and write it, eg eeprom.write(offset,eval(atob(data))) where data is the base64-encoded data. But this is where the wheels fall off - I don't have enough memory to eval it, because of how much space the array takes up. Even if i were to preface the data with 'new Uint8Array', it would still choke on making the intermediary array.
Am I forgetting about some more memory efficient way to get data into Espruino from an http request?
Is there a more efficient format I could use to store/send it?
Beta Was this translation helpful? Give feedback.
All reactions