Raspberry read serial data from Arduino over USB using NodeJS

Hello guys, I know this is not a 100% Blynk related subject, but I have spent many days searching for an answer without success and would like to know if you could help me =/

I am currently trying to configure the NodeJS on the Raspberry to read and store the values on Blynk virtual pins, currently the Arduino sends the following message over USB:

S1T1,2345,S1RSSI,-84,S1SNR,750

Where:
S1T1 = Means Sensor 1 Temperature 1;
2345 = Means 23,45 Celcius;
S1RSSI = Means Sensor 1 RSSI (Signal strenght);
-84 = Means the signal value -84;
S1SNR = Means Sensor 1 SNR (Signal strenght);
750 = Means 7.50 dBm.

As you can see below, I am able to receive the messages on Raspberry, but, I dont know how to allocate them into variables.

image

What I need is (I will try to describe as C++ as it works just fine in C++):

void loop()
{
Blynk.run();
//***********************************************************************************//
// If there is serial data, read and store
while (Serial.available() > 0) {

if (Serial.find("S1T1")) {
float t1 = Serial.parseInt();
float temp1 = t1/100;
Blynk.virtualWrite(V0, temp1);

//***********************************************************************************//
//Receive signal strength data
if (Serial.find("S1RSSI")) {
int rssi1 = Serial.parseInt();
Blynk.virtualWrite(V1, rssi1);
}
if (Serial.find("S1SNR")) {
float snr1 = Serial.parseInt();
float snrs1 = snr1/100;
Blynk.virtualWrite(V2, snrs1);
}
}

The NodeJS code I have so far:

const SerialPort = require('serialport');
const port = new SerialPort('/dev/ttyACM0', () => {
console.log('Port Opened');
});
const parsers = SerialPort.parsers;

const parser = new parsers.Readline({
delimiter: '\n'

});

port.pipe(parser);

parser.on('data', console.log);

Can you please help me adapting the NodeJS code to be able to do the same as the C++ stretch?

I am guessing you are looking for something like this…

etc.

I will check it out thank you, @Gunner.

1 Like