JavaScript on ESP32 - Duktape

User avatar
kolban
Posts: 525
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: JavaScript on ESP32 - Duktape

Postby kolban » Tue Jan 03, 2017 8:30 pm

Howdy,
Wow ... that was a blunder. The RMT.js should indeed be in the filesystem folder. The change will be in the next Github push ... thanks for that.

The Serial console is present and working ... just not documented yet. At a high level, when ESP32-Duktape boots, it will check an NVS value (namespace: esp32duktape, name: useSerial) and if the value is 1, it will NOT start bootWifi and the IDE but instead it will run the script called "uart_processor.js". This will start monitoring UART 2 (I believe it was 2) ...

When an HTTP request is made down UART 2 (HTTP seemed as good a protocol as any) then it will be "run" as a script. See the example under "tools" directory.

As you can see ... its all very rough around the edges. My hope was that by switching off WiFi and web server, I could scare up enough RAM to get Bluetooth working under JS ... unfortunately that isn't going to happen soon ... with my minimal environment, after loading Duktape, the best I can get (so far) is 70K free and switching on BT wants to eat 64K ... and that doesn't leave enough. So for the time being, JS and BT aren't going to play well together.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
Frida854
Posts: 14
Joined: Sat Dec 24, 2016 11:51 am
Location: Middelfart, Denmark

Re: JavaScript on ESP32 - Duktape

Postby Frida854 » Tue Jan 03, 2017 9:39 pm

After I have run the make in tools and started node uartScriptRunner.js -f txt.txt I got this:

Code: Select all

D (323688) log: Parsing completed
D (323689) log: Our accumulated data is: console.log("Hello!");
console.log("Free heap: " + ESP32.getState().heapSize);
D (323695) log: Command is: RUN
D (323707) modules: >> js_console_log called
D (323708) log: Console: Hello!
D (323709) modules: >> js_console_log called
D (323709) log: Console: Free heap: 72472
D (323720) log: We are ready to start parsing

I tried first with f but it did not work, then with -f and it ran.

Thank you
Yes Frida is my watchdog!

dmoshal
Posts: 1
Joined: Thu Jan 05, 2017 2:06 pm

Re: JavaScript on ESP32 - Duktape

Postby dmoshal » Thu Jan 05, 2017 2:20 pm

Hi Neil, excellent stuff, i particularly like the concept of bootstrapping a JS interpreter, and then building on that with JS.

Presumably once we figure out how to integrate sourcemaps and commonjs modules, then the whole NodeJs ecosystem becomes available (subject to platform constraints of course).

I've ordered boards from Aliexpress and Sparkfun, looking forward to helping you with this.

David

ps: really enjoying your latest book, thanks for that!

User avatar
kolban
Posts: 525
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: JavaScript on ESP32 - Duktape

Postby kolban » Fri Jan 06, 2017 3:20 am

Thanks David,
Its coming together nicely ... spent the last couple of evenings tinkering with SSL and that has worked out well. I am now able to make HTTPS requests which is essential for many REST requests ... in addition, I'm concurrently tinkering with I2C so that should be present shortly. RAM continues to be a challenge ... I spent last weekend getting enough of my head around BLE in pure C but when I started providing JavaScript wrapping, we ran out of RAM ... BLE seems to want at least 64K ... and SSL seems to want at least 20-40K ...

Today, when we provide a JavaScript script ... that is compiled into byte code which resides in RAM ... speaking with the awesome Duktape primary developer, he feels quietly confident that we may get Bytecode to be able to be written into flash ... so we will either compile outside of the physical ESP32 and flash the scripts into a flash area or else continue to compile on the ESP32 (as we do now) but the result will be written into flash ...

So there is good hope there ... In addition ... there is talk about a 4MByte RAM module for ESP32 coming 3Q17 which may make ALL these issues just disappear. My thinking is we'll keep plowing ahead with the assumption that one way or another the memory issues will resolve.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
kolban
Posts: 525
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: JavaScript on ESP32 - Duktape

Postby kolban » Sat Jan 07, 2017 4:56 am

Project Status: 2017-01-06
With the release of the I2C driver as part of the ESP-IDF, a first pass was made to integrate I2C support. Thankfully that worked first time with no serious issues. A world of questions was generated on I2C support though which will hopefully become clearer over time.

In other news, outbound SSL integration was added using the ESP-IDF "mbedtls" libraries. It took a bit of tinkering but in the end it worked out well. However, the persistent problem of available memory continues to plague us. Using SSL out of the box seems to want between 20K-40K per active connection. Combine that with a WiFi stack and Duktape ... and again we run out of RAM. Our sensitivity to low RAM continues to haunt us ... it means that we can't "sensibly" use SSL the way we want. We can disable a bunch of duktape memory consumers such as stack trace and line number recording which reduces RAM usage and gets SSL going happily, but I'd rather not have to perform these tasks. Hope springs eternal for Duktape memory reductions. Bluetooth is also unable to run properly because of RAM needs.

Thankfully, I2C wasn't a RAM user so anyone wanting high level access to I2C shouldn't have an issue.

And that's about it for this week. When SPI becomes available, we will add that too.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
kolban
Posts: 525
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: JavaScript on ESP32 - Duktape

Postby kolban » Wed Jan 11, 2017 5:28 pm

SPI support added
With the release of SPI drivers this week, I couldn't wait to add SPI support to our ESP32 JavaScript support. We now have embedded SPI APIs that are trivially accessible from JavaScript.

Docs for the SPI module can be found here:

https://github.com/nkolban/duktape-esp3 ... ses.md#spi

A sample showing driving a 8 digit LED counter can be found here:

https://github.com/nkolban/duktape-esp3 ... max7219.js

Hopefully as you can see, assembling solutions is becoming easier and easier (ignore the rats nest of wires on the breadboard ... all we actually need are 3 for this project - CLK, MOSI and CS ... plus a current source).


Image

Tags: SPI, LED, 7 segment, MAX7219, MAX7221, JavaScript
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
Frida854
Posts: 14
Joined: Sat Dec 24, 2016 11:51 am
Location: Middelfart, Denmark

Re: JavaScript on ESP32 - Duktape

Postby Frida854 » Tue Jan 17, 2017 1:18 pm

Today's download gives me 2 errors.
I have tried to change the lines, but the file is auto generated again, so what to do?

Code: Select all

CC extras/module-duktape/duk_module_duktape.o
In file included from /home/poul/Programmer/Duktape32/duktape-esp32/components/duktape/extras/module-duktape/duk_module_duktape.c:5:0:
/home/poul/Programmer/Duktape32/duktape-esp32/components/duktape/extras/module-duktape/duk_module_duktape.c: In function 'duk__resolve_module_id':
/home/poul/Programmer/Duktape32/duktape-esp32/components/duktape/src/duktape.h:453:127: error: right-hand operand of comma expression has no effect [-Werror=unused-value]
  (duk_error_raw((ctx), (duk_errcode_t) (err_code), (const char *) (DUK_FILE_MACRO), (duk_int_t) (DUK_LINE_MACRO), __VA_ARGS__), (duk_ret_t) 0)
                                                                                                                                  ^
/home/poul/Programmer/Duktape32/duktape-esp32/components/duktape/extras/module-duktape/duk_module_duktape.c:175:2: note: in expansion of macro 'duk_error'
  duk_error(ctx, DUK_ERR_TYPE_ERROR, "cannot resolve module id: %s", (const char *) req_id);
  ^
/home/poul/Programmer/Duktape32/duktape-esp32/components/duktape/extras/module-duktape/duk_module_duktape.c: In function 'duk__require':
/home/poul/Programmer/Duktape32/duktape-esp32/components/duktape/src/duktape.h:445:23: error: right-hand operand of comma expression has no effect [-Werror=unused-value]
  (duk_throw_raw((ctx)), (duk_ret_t) 0)
                       ^
/home/poul/Programmer/Duktape32/duktape-esp32/components/duktape/extras/module-duktape/duk_module_duktape.c:427:2: note: in expansion of macro 'duk_throw'
  duk_throw(ctx);  /* rethrow original error */
  ^
cc1: some warnings being treated as errors
/home/poul/Programmer/Duktape32/esp-idf/make/component_wrapper.mk:176: recipe for target 'extras/module-duktape/duk_module_duktape.o' failed
make[1]: *** [extras/module-duktape/duk_module_duktape.o] Error 1
/home/poul/Programmer/Duktape32/esp-idf/make/project.mk:382: recipe for target 'duktape-build' failed
make: *** [duktape-build] Error 2
Yes Frida is my watchdog!

User avatar
kolban
Posts: 525
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: JavaScript on ESP32 - Duktape

Postby kolban » Tue Jan 17, 2017 6:44 pm

Howdy Frida,
To hear is to obey. I was able to track down the breakages and affect repairs. If you could refresh from Github and try again ... if there are more problems, let me know ASAP. I had exactly the same problems as you reported ... so I am quietly hopeful that the fixes on my environment will translate to fixes on yours.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
kolban
Posts: 525
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: JavaScript on ESP32 - Duktape

Postby kolban » Sat Jan 21, 2017 11:30 pm

Project status: 2017-01-21
Progress continues. A new build/compiled release has been distributed with all the latest goodies ... see:

https://github.com/nkolban/duktape-esp3 ... llation.md

The latest goody that has been added is interrupt driven GPIO. We can now register a JavaScript callback function to be invoked automatically when a GPIO interrupt has been triggered.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

User avatar
kolban
Posts: 525
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: JavaScript on ESP32 - Duktape

Postby kolban » Mon Jan 23, 2017 12:34 am

Video: ESP32-Duktape as a Web Server

New You Tube video now available showing ESP32-Duktape as a web server.

https://www.youtube.com/watch?v=DsuDcYnQB2U
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Who is online

Users browsing this forum: No registered users and 1 guest