Skip to content

Instantly share code, notes, and snippets.

@phoddie
Last active July 14, 2019 00:44
Show Gist options
  • Save phoddie/17601031d83602f688c20c98292c622e to your computer and use it in GitHub Desktop.
Save phoddie/17601031d83602f688c20c98292c622e to your computer and use it in GitHub Desktop.
etherport option for firmata.js repl
#!/usr/bin/env node
const firmata = require("./lib/firmata");
const Etherport = require("Etherport");
const repl = require("repl");
console.log('Enter USB Port or "etherport" and press enter:');
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.once("data", (chunk) => {
chunk = chunk.replace("\n", "");
const port = ("etherport" === chunk) ? new Etherport(3030) : chunk.replace("\n", "");
const board = new firmata.Board(port, () => {
console.log(`Successfully Connected to ${port}`);
repl.start("firmata>").context.board = board;
});
board.on("string", msg => console.log(`Board message: ${msg}`));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment