Elk IDE

Elk IDE is a JavaScript based firmware development environment.

This is an alternative way of building ESP32 device firmware, in addition to ESP-IDF, Arduino IDE, and other. It is similar to Arduino IDE, but uses Elk restricted JavaScript engine as a programming language.

Unlike traditional enviromnents, Elk IDE does not need to compile or flash the firmware, therefore edit/run cycle in ELk IDE is very fast. Re-running the code takes less than a second.

Download and install

OS Download Instructions
Windows Elk-IDE.win.zip Download and unzip to C:\. Start C:\ElkIDE\ElkIDE.exe
MacOS Elk-IDE.macos.zip Unzip, double-click on Elk-IDE

Quick start guide

  1. Download and start Elk IDE
  2. Login to mdash
  3. Click on Flash device button
  4. In the dialog, choose serial port, enter WiFi credentials and click Flash
  5. When flashing process completes, login to https://mdash.net
  6. Your device should appear "green" (online) on mDash dashboard:
  7. In the Elk IDE, change the LED pin number for your device:
     let state = {pin: SET_YOUR_LED_PIN, on: false };
  8. Go back to Elk IDE, select online device.
  9. Click Run to execute JS code on your device. LED must start blinking:

Architecture

A diagram below shows the overall Elk IDE framework:

ELK IDE

  • Elk IDE starts, authenticates to mDash and fetches user's device list.
  • User selects a device.
  • When user presses on 'Run' button, ELK IDE sends JS code by calling JS.Exec() function on a selected device
  • The JS.Exec function kills a currently running Elk JS instance, starts a new one, and executes user's code in a new JS instance

The elk-base firmware:

  • Uses https://github.com/cesanta/elk library that implements Elk JS engine
  • Uses https://github.com/cesanta/mDash library to connect to mdash.net
  • Implements a low-level JS API via a set of JS drivers located in api.js
  • When Elk IDE flashes new device, it flashes elk-base firmware, and creates a filesystem with
    • api.js file, which contains JS API
    • mdash.cfg file, which contains WiFi and mDash device credentials

Download locations:

  • elkfw.zip - a current build of elk-base firmware
  • api.js - a part of elkfw.zip, amalgamated JS drivers

API

Timer.set(milliseconds, flags, callback, param)

Setup timer with milliseconds timeout. flags is a bitmask of the following values:

  • Timer.REPEAT - callback is invoked periodically until the timer is deleted using a Timer.del() call. If not specified, a callback is invoked only once.
  • Timer.NOW - invoke callback immediately

Return: numeric timer ID suitable for Timer.del(). Example:

// Call every second (1000 milliseconds)
let id = Timer.set(1000, Timer.REPEAT, function() {  
  Sys.log('hello');
}, null);

Timer.del(id)

Cancel previously installed timer. Return: none.

Timer.millis()

Return number of milliseconds since power up.

Sys.log(message)

Send log message - to the cloud, or to the serial console if disconnected. level is from 0 to 3. Message must be a string. Return: none.

Sys.ram()

Return free memory in bytes.

GPIO.mode(pin, mode)

Set GPIO pin mode. pin is a numeric GPIO pin number. mode can be either GPIO.INPUT or GPIO.OUTPUT. Return: none.

GPIO.pull(pin, type)

Set GPIO pin pull type. pin is a numeric GPIO pin number. type can be either GPIO.NONE, GPIO.UP, or GPIO.DOWN.

GPIO.write(pin, level)

Set GPIO pin level to either 0 or 1. Return value: none.

GPIO.read(pin)

Read GPIO pin level. Return value: 0 or 1.