Node library for interfacing with espruino javascript microcontroller.
npm install node-espruinonode-espruino
=============
An easy to use node module for interfacing with a micro controller running espruino as well as a cli.
Available as a Grunt task.
Using from node
---------------
``
`
var nodeEspruino = require('node-espruino');
var espruino = nodeEspruino.espruino({
comPort: 'COM4'
});
espruino.open(function(){
espruino.command('1+2', function(result){
console.log(result);
});
});
`
Using from shell
----------------
Install.
`
npm install node-espruino -g
`
Use.
`
$ echo 'digitalWrite(LED1, true);' > led.js
$ espruino upload led.js --save
`
if you know the serial number of the board, you can refer to it by serial:
`
$ espruino upload led.js --save --boardserial '33FFD605-41573033-15720843'
comPort
API Reference
-------------
$3
Returns a new espruino. or boardSerial must be specified. Before any communication can
open
be made to the espruino board the function must be called, which acepts a callback to be
comPort
executed on completion.
#### options
boardSerial
COM address to connect to.
done
Serial (as in board manufacturer serial number, not COM port.)
of board you want to connect to.
#### methods
##### function open( function done(err) )
This function must be called before any other function, it opens communication to the espruino board.
Accepts a callback to be run when communication is established.
##### function command(text, function done(result) )
Executes text on espruino, calls on completion with result of command.
done
##### function reset(done)
Resets boards memory to default, dumping all loaded code. is a callback that executes after reset completes.
done
##### function save()
Saves loaded code to flash. Preserves after board hard reset and loss of power. is a callback that executes after reset completes.
options
##### function upload(code, options, function done() )
:
save: [true| false]
* whether to save the loaded code to the to the espruinos onboard flash.
uploadModules: [true | false]
* if true, module requires are parsed out of code and uploaded.
moduleDir: 'Path'
* the root directory to look for modules.
code
Convenience function. Parses out modules from code and loads from disk, resets board, then uploads .
require('name')
##### function dump(function done(result))
Dumps loaded code from espruino.
##### function addModule(name, code, function done)
Adds a module with the specified name and code to the espruino. It can then be loaded by
running on the espruino.
code
##### function clearModules(function done)
Clears all loaded modules from espruino.
##### function parseModules(code)
Returns an array of all modules defined in . Parses out require('module') from input code.
.on('data', function callback(data) )
##### function close(function done() )
Closes serial connection to espruino.
#### events
--port [COM Port]
when espruino writes data back over serial, callback is called with data.
CLI Reference
----------------
$3
--boardserial [Board Serial No]
--listen
upload [file] --save
If listen is specified, after the command is completed we will leave the serial connection open and print from the espruino.
$3
save` is specified the uploaded code is saved to flash.
Flashes the specified file to the espruino. If