- Notifications
You must be signed in to change notification settings - Fork9
"Lightweight" JS interpreter for ESP32. Provides JS-based eventloop implementation and native asynchronous network and timer functions.
License
marcelkottmann/esp32-javascript
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
"Lightweight" JS interpreter for ESP32. Provides JS-based eventloop implementationand native asynchronous network and timer functions.Because of the limited memory on ESP32-WROOM modules, the full functionality is currently only realizable on ESP32-WROVER and ESP32-S2-WROVER modules, that came with at least 2MB integrated SPIRAM.
Installesp-idf 4.2.2 on your system.
Clone esp32-javascript inside your esp directory (normally ~/esp):
cd~/esp git clone https://github.com/pepe79/esp32-javascript.git
Change into ~/esp/esp32-javascript
cd~/esp/esp32-javascript
Maybe you want to change the BOARD_VARIANT in the ./CMakeLists.txt filefor the integrated arduino-esp32 bindings.
First build the project with
#for ESP32 devices idf.py build#for ESP32-S2 devices idf.py -DIDF_TARGET=esp32s2 build
Connect your ESP32 Dev Board via USB and run
idf.py flash monitor
Use the keyboard shortcutAltGr + ] to leave serial monitor.
Now you have installed the pre-configured boot script.
If this is your first install, your onboard LED should blink now. Blinking signals that your board has started a soft ap with the ssid "esp32". With your mobile or desktop connect to the WLAN SSID "esp32" and openhttp://192.168.4.1/setup (if you have not changed the default credentials your username / password is esp32 / esp32 ). You can change the default password infirmware-config.ts by changing the value of keypassword.
On the Setup page you can configure your WLAN settings and an URL to download your JS main script from.
Please note that the Javascript OTA script, does not need to have a main function, because its evaluated entirely.That means, to print out "Hello World", you only have to include one line in your script on the webserver:
console.log("Hello world!");
You can test this example by configuring this URL as "Javascript OTA":https://raw.githubusercontent.com/marcelkottmann/esp32-javascript/master/examples/example.js
Please see also the other example in./examples
If you need to create your own C/C++ bindings for your JS code, this are the steps to perform:
- Create a file named
project.cppin the./maindirectory - Implement the esp32_javascript_main callback function inside this
project.ccp:
#include"esp32-javascript.h"externvoidesp32_javascript_main(duk_context*ctx) {// do your own duktape bindings here }
SeeDuktape Programmer's Guide for more information regarding Duktape bindings.
If you need more than this, you can create your own esp-idf component below./components. Then delegate theesp32_javascript_main function to this component.Additionally you have to set your component name in the top level./CMakeLists.txt. Refer to the documentation next to the settingESP32_JS_PROJECT_NAME.SeeESP Build System for information on how to create a component with the esp-idf build system.
You can perform a native firmware OTA upgrade by calling the URL /setup . There is a section called "Native OTA" where you can provide two urls to the new images: One for the actual firmware image (normally named esp32-javascript.bin in your build directory) and the other for the JS modules image (normally named modules.bin in your build directory).
The upgrade is performed in the background. You can check the upgrade status either by staying on the upgrade page, which is reloaded automatically every ~20 seconds or click on "Upgrade status" in the setup page.
After upgrade has finished you have to restart the device to load the new firmware.
You can clean the project by executing
idf.py fullclean
If you want to use all the esp32-javascript defaults for your sdkconfig. Remove./sdkconfig file. This file will be recreated the next build with all the defaults.
You can erase the persistent flash memory, which will be equivalent to a factory reset, by executing
idf.py erase_flash
- Supported chips ESP32 and ESP32-S2
- 2 MB Minimum Flash Size
- 2 MB Minimum external SPI RAM (WROVER)
| Version | Compatible |
|---|---|
| 4.2 | ☑️1 |
| 4.2.1 | ☑️1 |
| 4.2.2 | ✅ Recommended |
1 SSL client connections currently not working properly for ESP32-S2 devices due to esp-idf bug in 4.2.x:espressif/esp-idf#6998 , but can be fixed manually (see changes in PR).
Theexamples directory contains arepl that can be used as JS OTA Url:https://raw.githubusercontent.com/marcelkottmann/esp32-javascript/http-streaming/examples/repl.js
The repl can be used with netcat directly or with a combination of rlwrap and netcat to have a history-support:rlwrap netcat [IP-ADDRESS] 1234
Enter username and password separated with colon(:) to authenticate, e.g.esp32:esp32 + Enter
~/esp/esp32-javascript> rlwrap netcat 192.168.188.24 1234> esp32:esp32====> authorized.> console.log('Hello world.')LOG|Hello world.====> undefined>
Update documentation by executing
npm run doc
See source files.
About
"Lightweight" JS interpreter for ESP32. Provides JS-based eventloop implementation and native asynchronous network and timer functions.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
