Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var rpio = require('rpio');
var firmata = require('firmata');
// GPIO18 low -> Arduino reset off
rpio.setOutput(12);
rpio.write(12, rpio.LOW);
// start connection to Arduino
// USB: /dev/ttyUSB0 or /dev/ttyACM0
// UART: /dev/ttyAMA0
var board = new firmata.Board('/dev/ttyAMA0', function(err)
{
if(err)
{
console.log(err);
return;
}
console.log('connected');
board.pinMode(13, board.MODES.OUTPUT);
// switch on LED
board.digitalWrite(13, board.HIGH);
// switch off LED after 3s
setTimeout(function()
{
board.digitalWrite(13, board.LOW);
process.exit(0);
}, 3000);
'experimental at best. Have fun! :)'
);
setupConnection('experimental-board', board);
board.on('ready', (error) => {
if (error) {
callback(error);
} else {
updateConnection('experimental-board', board);
callback(null, board);
}
});
return;
}
console.info('Connecting to port "%s"', port);
const board = new Board(port, (error) => {
if (error) {
console.info('Board setup error');
callback(error);
} else {
updateConnection(port, board);
callback(null, board);
}
});
setupConnection(port, board);
board.on('error', (error) => {
// TODO: look up docs/source code for this
console.info('Board error event!');
console.log(error);
});
var firmata = require("firmata");
var repl = require("repl");
var serialport = "/dev/ttyUSB0";
var red = 0, green = 0, blue = 0;
var board = new firmata.Board(serialport, function (error) {
if (error) {
console.log(error);
return;
}
console.log('Connected to ' + serialport);
console.log('Firmware: ' +
board.firmware.name + '-' +
board.firmware.version.major + '.' +
board.firmware.version.minor
);
var context = repl.start("RGB>").context;
// context.sses = sendSysExString;
context.sendPixel = sendPixel;
context.rainbow = rainbow;
// Board({ port: path String })
//
// Board()
// ie. auto-detected
//
path = portOrPath;
}
// Add the usb device path to the list of device paths that
// are currently in use - this is used by the filter function
// above to remove any device paths that we've already encountered
// or used to avoid blindly attempting to reconnect on them.
Serial.used.push(path);
try {
io = new IO(portOrPath, function(error) {
if (error) {
caught = error;
}
callback.call(this, caught, caught ? "error" : "ready", io);
}.bind(this));
// Extend io instance with special expandos used
// by Johny-Five for the IO Plugin system.
io.name = "Firmata";
io.defaultLed = 13;
io.port = path;
// Made this far, safely connected
isConnected = true;
} catch (error) {
var mqtt = require('mqtt');
VirtualSerialPort = require('mqtt-serial').SerialPort;
client = mqtt.connect(n.mqttServer,
{username: n.username, password: n.password});
client.on('error', function(err){
node.warn(err);
});
sp = new VirtualSerialPort({
client: client,
transmitTopic: n.pubTopic,
receiveTopic: n.subTopic
});
node.io = new firmata.Board(sp, {samplingInterval: 300, reportVersionTimeout: 15000});
start(node);
}catch(exp){
console.log('error initializing mqtt firmata', exp);
process.nextTick(function() {
node.emit('ioError', exp);
});
}
}
else if(n.connectionType === 'tcplisten'){ //mode listen network
node.tcpServer = net.createServer(function(socket){
node.io = new firmata.Board(socket);
start(node);
console.log('client ready', socket.remoteAddress + ":" + socket.remotePort );
socket.emit('open', {});
socket.on('error', function(err){
function connect(port) {
console.info('Connecting to port "%s"', port);
const board = new Board(port, function(err) {
if (err) {
console.error('Failed connecting to port %s', port);
throw err;
}
callback(board, port);
});
}
}