I'm trying to get a message from my Arduino to NodeJS using SerialPort. Here is my NodeJS code:
var SerialPort = require('serialport');
var port = new SerialPort('/dev/tty.usbmodem1421',{
baudRate: 9600
});
port.on('data',(data) => {
console.log(data);
});
And here is my Arduino code:
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("Message");
delay( 1000 );
}
It's working. However, the message I am receiving looks like this:
<Buffer 4d 65 73>
<Buffer 73 61 67 65>
<Buffer 0d 0a>
I've tried a lot of different things to try and read the message properly. If it makes a difference I would eventually like my message to be JSON. Here are a few things I have tried:
I've added this:
parser: SerialPort.parsers.readline('\r\n')
I think that might be out dated, as I get readline is not a function errors messages.
I have tried using a Readline object:
var parser = new Readline();
parser.on('data', function(data){console.log( data );});
Any help would be very much appreciated!