-
@Kolban the guys from nodemcu had the same problem and fixed it. Heap doubled from one day to the other.
@Gordon source is available here http://jumspruino.jumware.com/sources/SHA1.js.
I did some (crazy) things to reduce memory and speed, which did not make it easier to read:- use typed arrays
- remove temporary values
- replace switch by if...elseif...
- removed functions and added code inline
- reuse local vars
- converted multiplication(like *4, *32,..) to shift
- removed a "funny" encode64 and use btoa instead
- moved functions to be local
All together my plan is to use ESP8266 for web, and let Espruino boards do the hard work.
- use typed arrays
-
Tested new version(1v81.705) immediately :-)
For websocket SHA1 is needed, this was my choice to compare benefit:- old SHA1 duration was 1390ms and process.memory().free after calling was 735
- after a lot of changes it's 1047ms and 823 blocks are free
- now with new firmware version it takes 1290ms and 866 blocks are free
So for this function it uses less memory (20%) and is slower (20%), interesting result.
- old SHA1 duration was 1390ms and process.memory().free after calling was 735
-
First of all, I would like to have more options to extend firmware by myself. Let me add my 2 cents:
- adding all modules to Espruino Firmware that are helpful to somebody makes development and maintenance a nightmare. Who would be (or at least feel) responsible ? If I would be Gordon, my answer would be "not me anymore".
- modules like neopixel can be big or small. There are some implementation for WS2812 and others that give a lot of options. Which one should be implemented in Espruino ?
- some modules are helpful on special platform only. For example, Espruino boards already supports WS2812, why should there be one more module ?
- Espruino already supports binarys, see http://www.espruino.com/Assembler and http://www.espruino.com/Compilation.
- binarys are machine code, therefore we will never have binarys running on all platforms.
- by working with WebSockets I would like to have SHA1 implemented, to give one more example
- something I was working on some time ago was a PID, one more example
- some already available function in Espruino are needed by few people only, like FFT, CC3000, tv, ...
What I could imagine is something like this:
- use compiler of WebIDE to get a code-frame (function mytest(a,b){ return a+b;}) in a cpp file
- add C-code to do whatever somebody wants to do inside
- compile and upload this binary
- or take binarys, that somebody else created
Right now we have some limitations, even I know about
- we need actual exports from process.env. This will change with each new release. So we need a more general way to get this information.
- binarys right now are stored in memory not in flash.
- at least in assembler we can store local variables inside the binarys, a nogo for flash
- we don't get C-code from actual compiler service
- compiler service works for Espruino(ARM?) only, there is nothing similiar available for ESP8266, EMW3165, NRF52, ...
- adding all modules to Espruino Firmware that are helpful to somebody makes development and maintenance a nightmare. Who would be (or at least feel) responsible ? If I would be Gordon, my answer would be "not me anymore".
-
@allObjects I have been at the same point some days ago.
What I did is to connect GPIO2 to a serial port of an Espruino Board.
Espruino starts this application:var d = "",epc = []; Serial3.setup(115200,{rx:C11}); Serial3.on('data', function(data) { var i = 0; d += data; i = d.indexOf("\n"); if(i > 0){ if(d.substr(0,i).indexOf("epc1=") >= 0){ epc.push(d.substr(0,i)); } console.log(d.substr(0,i)); d = d.substr(i+1); } if(d.length >= 128) { console.log(d); d = ""; } });
In my case Espruino is connected to a local copy of WebIDE and ESP8266 is connected to the original WebIDE.
Debugging need to be switched on with require("ESP8266").logDebug(true) -
First version of WebIDE supported filehandling for local files. There are a lot of restrictions inside chrome because of security. One of them is you have to select files manually. There is no way to store or load a file without manually selecting this file in selectbox. Nothing like "file://C:..." works.
In a later version projects plugin was added. In this a local sandbox needs to be assigned. Chrome supports handling of files and directorys in a sandbox much better compared to ordinary files.
One example is searching for modules. In source window the command require("modulname") is used to search inside local sandbox for this module. Open a file by name without manual interaction is impossible. If you know a way, please let me know. I would be very interested.
Another example is the projects tab. You get a list of existing js-projects and load this into your editor. The plugin remembers this name and once you open the project-folder again, there is a save button for this project. SaveAs is supported by typing a new name into the textbox at the bottom of the list and click the save button.
Both options follow a different philosophy and have their pros and cons, take the one, which fits best for you. -
@tve Flash info tells me, I can store something there using peek and poke.
Another option to use is the Flash class: http://www.espruino.com/Reference#Flash
Gordon uses this area to store assembler functions there. I know, assembler in Arm and in ESP8266 is different, so this would take some more work. BTW, some time ago I created an assembler version of Flash class (to have fun and learn )
Using a 4MB flash version, data logger could store some data in this area.
Oh, just see, Flash is not supported for ESP8266 (yet?) -
@DrAzzy , you are the guy behind bigram and a lot of other good things.
If its not you, who else would have a chance :-)
Or to say with other words:
Gentlemen we found this guy and 3 people dead, all murdered by knife. We all know, how perfect he works with his knife. Ok, we did not find his knife.
Anyway, who cares about details?
Gentlemen, we have a rope and a horse. There is a tree, do we really have to wait for the court ? -
@tve see process.memory() from Espruino board V1.3
Some explanation is here- http://www.espruino.com/STM32F1Flash#line=13,24,27
hope, this helps a bit
process.memory();
={ "free": 2222, "usage": 28, "total": 2250, "history": 14,
"stackEndAddress": 536910336, "flash_start": 134217728, "flash_binary_end": 228024, "flash_code_start": 134449152, "flash_length": 262144 }
- http://www.espruino.com/STM32F1Flash#line=13,24,27
-
-
Had the same idea first.
But, .... we would need a server for that, which may not be available in my WiFi at home.
Another point is additional memory consumption during http get, which is a lot.
At least compared to available memory on ESP8266.
During testing, I used process.memory().free, to watch this.
BTW, forgot to mention, uploading my example needs minimizing. -
@Gordon is right, I used the HTTP server to get headers parsed.
BTW, is there an easy way to encode/decode socket frames ? Socket itself delivers raw data and I had to seperate the data part oit of it.
I don't know how node.js handles this, but can imagine that code for this already exists somewhere around http handling. (sorry lack of C-handling, tried to find and failed.
May be we could have an option to switch on/off decoding/encoding ?
To be honest, even this short sha1 takes a lot of memory, at least at runtime.
Had to use some "optimization" to get it running. And it takes some time to calculate.
Therefore I would prefer to have sha1 in firmware, same way we have sha224 and sha256.
And if there is a nicer way to do encode64, please give me a hint. -
The compiler/assembler won't work in ESP8266 at all. It's a different
architecture so would be a nightmare to support I'm afraid.It's a total different structure, as fas as I could follow @nkolban. therefore nothing, compiled for Espruino will run on ESP8266.
May be @DrAzzy has an idea, how this could be supported. A lot of information is available in process.env, and together with a compiler somewhere.... you never know.
This would take away the idea of one source running on all platforms, but I'm pretty sure, this idea is not carved in stone on a long term.
Anyway, it is a part of my wishlist only. Not all wishes become true, especially those where others have to do the work. Ask my lady about her garden, if you want to compare with daily life ;-) -
If I had a wish on this my list would be something like this. Others will have other wishes, but for now, I'm the first one to ask ;-)
- add sdcard support. I'm working on a datalogger which collects data from sensors, stores on SD and prepares this data for JSON-calls from web client.
- using flash for files, @tve talked about using flash for files, similiar to what nodemcu is doing.
- have a plugin-interface in Espruino to add modules/functions. @Gordon already startet something like this with assembler and compile in original Espruino.
- add flash-information to process.memory(), as original Espruino does.
- for nodemcu there is a webpage to create "your own binary". Functions can be added or removed there. For example, if you don't need SPI or IC2, remove it and add, may be SHA1 support or other special things. This is a big big wish, I know.
- add sdcard support. I'm working on a datalogger which collects data from sensors, stores on SD and prepares this data for JSON-calls from web client.
-
@sameh.hady, may be we can share our experience. Base is the same, since my knowledge of C is poor. May be waiting for somebody adding a server to Espruino, as suggested by @Gordon, would be a better way. But at least I learned a lot around datahandling with sockets ;-)
I've found an SHA1 implementation and added it to my testing environment around Espruino on ESP8266. You can find my actual source here:- http://jumspruino.jumware.com/sources/ESP8266Test.js, see function startSocket and SHA-functions.
- http://jumspruino.jumware.com/sources/WebSocket.htm
This is far away from being perfect, but it includes SHA1 and decoding/encoding for socket frame. Its tested in my environment with firefox and chrome. For connection I use the http-module from Espruino, which makes it easy to handle headers.
Todo list, please have in mind, very early status: - keep connection alive
- socket frame for data > 200 bytes
- problem with IE, which sends uppercase chars in upgrade header.
- testing, testing, testing
- .....
- http://jumspruino.jumware.com/sources/ESP8266Test.js, see function startSocket and SHA-functions.
-
@tve, you exactly hit my point.
I will have a lot of data from several sensors. This data is used to create charts. Charts are updated, whenever new data is comin in. This is something, often used in controlrooms.
With websockets the amount of data to be send are only a few bytes.
Having a cloud in the background would go over the top. And I would loose some control. -
Just playing around a bit with websockets.
I wonder if there is a way to create a websocket server on Espruino.
Right now my problem is to calculate SHA1-hash from a given Sec-WebSocket-Key, to initiate a connection between client and server.
There are some sources available, but it would take away a lot of available memory. -
Before flashing you have to connect gpio0 (GPIO zero) to low and do a hardware reset.
On the board you can see the blue LED flashing shorter if in Flash mode.
After flashing remove this connection before doing hardware reset.
If there is a problem during flashing, the circle on left bottom becomes red.
In this case retry and sometimes its better to flash both files seperately. -
@Gordon is there a way to get linenumber in debug output ?
I'm testing how to get a simple debugger as plugin for webIDE.
Right now it's more or less a collection of buttons, replacing typing commands, so nothing fancy.
It would be a big help, to get linenumber for highlighting in editor-window. -
-
-
-
Hello Kolban,
following your description, it is somewhere between alpha and beta.
Thats not a problem for me, I would like help testing.
For wifi functions I will wait for your "ready for testing".
Some minutes ago, flashing of my ESP201 ran fine. So I could do some testing with I/O too. For that I will wait until some more information about testworthy functions is available.Up to now I got these simple javascript running in my first test:
var i = 7; i++; console.log(i); for(i = 0; i < 5; i++){ console.log(i); } function hello(t){ console.log("hello " + t); } hello("Hugo"); function hello2(n){ var me = this; me.n = n; me.show = function(t){ console.log(n + " " + t); }; } hello2.prototype.showNumber = function(){console.log(this.n + 3);}; var h = new hello2(42); h.show(" is the answer"); h.showNumber(); console.log(process.memory()); var si = setInterval(function(){ hello(i++); if(i > 8) clearInterval(si); },1000);
-
Hip hip hurray, I've just got Espruino running on ESP8266 ESP-01.
I used the nodemcu-flasher
Only change I had was to flash ESP8266_ox00000.bin and ESP8266_0x10000.bin seperately. It didn'twork with both in one session.
First (minor problem) was baudrate, it had to be switched to 115200 and now WebIDE works.
First feedback is below, I will start testing immediately.>process.memory(); ={ "free": 984, "usage": 39, "total": 1023, "history": 28 } >
Thanks a lot for this beautiful job to Gordon, Kolban, aplikatika and all others that have been involved !!!!
-
upload this simple application and get a list of files on SD
upload same 2nd time and get ERROR: Unable to list files : DISK_ERR
upload same 3rd time and get ERROR: Unable to mount SD card : NOT_READY
After HW reset, story starts again