Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

espruino

Package Overview
Dependencies
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

espruino

Command Line Interface and library for Communications with Espruino JavaScript Microcontrollers

  • 0.0.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
25
Maintainers
1
Weekly downloads
 
Created
Source

Espruino Tools

This repository contains a set of tools for the Espruino JavaScript Interpreter. Mainly, it is used by the Espruino Web IDE although hopefully it is portable enough to be used by other tools such as command-line interfaces.

Command-line

When installed as a Node module with npm install -g espruino you get a command-line tool called espruino:

USAGE: espruino ...options... [file_to_upload.js]

  -h,--help               : Show this message
  -v,--verbose            : Verbose
  -q,--quiet              : Quiet - apart from Espruino output
  -m,--minify             : Minify the code before sending it
  -p,--port /dev/ttyX     : Specify port(s) to connect to
  -f firmware.bin         : Update Espruino's firmware to the given file
                              Espruino must be in bootloader mode
  -e command              : Evaluate the given expression on Espruino
                              If no file to upload is specified but you use -e,
                              Espruino will not be reset

For instance:

# Write a program to Espruino (IF Espruino is the only serial port reported)
espruino myprogram.js

# Otherwise you'll want to specify the exact port first
espruino -p /dev/ttyACM0 myprogram.js

NPM Module

This is the NPM module espruino

It contains the following functions:

var esp = require("espruino");

/** Initialise EspruinoTools and call the callback.
 When the callback is called, the global variable 'Espruino'
 will then contain everything that's needed to use EspruinoTools */
esp.init(callback);

/** Send a file to an Espruino on the given port, call the callback when done */
esp.sendFile (port, filename, callback);

/** Execute an expression on Espruino, call the callback with the result */
esp.expr(port, expr, callback(result));

/** Flash the given firmware file to an Espruino board. */
esp.flash(port, filename, callback);

For example, to get the current temperature of the board you can do:

require('espruino').expr('/dev/ttyACM0', 'E.getTemperature()', function(temp) {
        console.log('Current temperature is '+temp); 
});

Note: this module is currently a bit noisy - it prints a lot of debug information to console.log when working.

Internals

This isn't well documented right now, but basically:

  • You have a bunch of source files that are automatically run
  • These add things to Espruino.Core or Espruino.Plugins
  • You then call into those to do what you want

It's not ideal for node.js, but was designed to run in the Web browser for the Espruino Web IDE

To Do

While EspruinoTools has been in use in the Web IDE for a while, the command-line tool still needs a lot of work.

Main things that need attention at the moment are:

  • The local filesystem should be checked for modules that are referenced from Espruino's code, maybe modules folder to avoid confusion with node.
  • Remove usage of console.log and replace it with something else that can be easily disabled when used as a module
  • Proper 'terminal mode' where you can interact with Espruino directly from the command-line

Cool stuff would be:

  • Add a command-line option (-w?) to watch a file and re-upload it when it has changed
  • Add an option to expose the serial connection via WebSockets. Something like the online Web IDE could the communicate directly.
  • Support for Nordic UART via bleat
  • Support for using the Espruino JS->C compiler offline, if arm-node-eabi-gcc is installed.

Contributing

Contributions would he hugely appreciated - sadly I'm stretched a bit thin with Espruino, Espruino's modules, the Web IDE and forum, so this isn't getting the love it deserves.

Please be aware that the Espruino Web IDE (and even a truly online version of the Web IDE depend heavily this code - so try not to do anything that will break them).

Code Style

  • Please stick to a K&R style with no tabs and 2 spaces per indent
  • Filenames should start with a lowerCase letter, and different words should be capitalised, not split with underscores

Code Outline

  • Core functionality goes in core, Plugins go in plugins. See plugins/_examplePlugin.js for an example layout
  • Plugins/core need to implement in init function, which is called when the document (and settings) have loaded.
  • Plugins can respond to specific events using Espruino.addProcessor. For instance you can use Espruino.addProcessor("transformForEspruino", function (data,callback) { .. }) and can modify code before it is sent to Espruino. Events types are documented at the top of espruino.js
  • Config is stored in Espruino.Config.FOO and is changed with Espruino.Config.set("FOO", value). Espruino.Core.Config.add can be used to add an option to the Settings menu.

Keywords

FAQs

Package last updated on 18 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc