Chat freely about the open source Javascript projects for ESP8266

User avatar
By sfranzyshen
#84752
sfranzyshen wrote:from the same people who brought you mongoose-os, mdash, mjs, and others ...

Elk: a restricted single-file JS engine for embedded systems https://github.com/cesanta/elk

it can be used from within the arduino development environment ...


I can confirm that 0.0.16 builds and runs on the esp8266 and esp32 platforms ...

Code: Select allUsing library elk at version 0.0.16 in folder: /home/name/Arduino/libraries/elk

esp8266
Code: Select allSketch uses 280664 bytes (26%) of program storage space. Maximum is 1044464 bytes.
Global variables use 28552 bytes (34%) of dynamic memory, leaving 53368 bytes for local variables. Maximum is 81920 bytes.

esp32
Code: Select allSketch uses 231185 bytes (17%) of program storage space. Maximum is 1310720 bytes.
Global variables use 16396 bytes (5%) of dynamic memory, leaving 311284 bytes for local variables. Maximum is 327680 bytes.

Test Code
Code: Select all#include "elk.h"  // Add Elk library

extern "C" void myDelay(int milli) { delay(milli); }
extern "C" void myWrite(int pin, int val) { digitalWrite(pin, val); }
extern "C" void myMode(int pin, int mode) { pinMode(pin, mode); }

struct js *js;

void setup() {
  js = js_create(malloc(700), 700);
  js_import(js, "f1", (uintptr_t) myDelay, "vi");
  js_import(js, "f2", (uintptr_t) myWrite, "vii");
  js_import(js, "f3", (uintptr_t) myMode, "vii");
  js_eval(js, "f3(2, 1);", 0);  // Set LED pin to OUTPUT mode ... tried f3(2, 2) also ...
}

void loop() {
  js_eval(js, "f1(200); f2(2, 1); f1(200); f2(2, 0);", 0);
}