I'm using nodejs for my rfid that is hook up on my raspberry pi. What I'm trying to do is when I tap the id "6f124628" the led won't turn on unless another pin on the arduino is high. I'm using firmata protocol for arduino communication.
JS:
function arduinoReady(err) {
if (err) {
console.log(err);
return;
}
console.log('Firmware: ' + board.firmware.name +
'-' + board.firmware.version.major +
'.' + board.firmware.version.minor);
var ledOn = true;
board.pinMode(ledPin, board.MODES.OUTPUT);
rc522(function(rfidSerialNumber) {
console.log(rfidSerialNumber);
if (rfidSerialNumber == "216264a9") {
onjie.writeSync(1);
}
data = board.digitalRead(ledPin);
if (rfidSerialNumber == "6f124628" && data == "board.HIGH") {
LED1.writeSync(1);
return;
}
});
But my code doesn't work and Typerror :
"listener" argument must be a function
var http = require('http').createServer(handler);
app.listen(8080);
function handler (req, res) {
fs.readFile(__dirname + '/firmata.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading firmata.html');
}
res.writeHead(200);
res.end(data);
});
}
The problem is with the method
createServer
You have to change the initialization of your method
handler
Try changing the
handler
declaration to this:And now, you're able to declare your server with: