I am using an Arduino Uno and a DTH11 temperature sensor to read tempearaturetemperature and then send that value to a computer via the serial port.
A nodejsNodeJS application is running inon the computer and capturecaptures that value and writewrites to a log file.
Here whenWhen I try to get values from my NodejsNodeJS application, sometimes the value is broken into two values. Eg: 25 -> 2 and 5
This is my arduinoArduino code:
dht DHT;
#define DHT11_PIN 7
float tem [4];
void setup() {
Serial.begin(9600);
pinMode(12, OUTPUT);
}
void loop()
{
int chk = DHT.read11(DHT11_PIN); //
int val = (int)(DHT.temperature);
Serial.println(val);
delay(600000);
}
This is my NodejsNodeJS program.
var fs = require('fs')
var logger = fs.createWriteStream('/data/Temperature/temperature.csv', {
flags: 'a' // 'a' means appending (old data will be preserved)
})
var SerialPort = require("serialport")
var serialPort = new SerialPort("/dev/ttyACM0", {
baudRate: 9600,
});
serialPort.on("open", function () {
serialPort.on('data', function(data) {
var moment = require('moment');
var dayTime = moment().format('YYYY-MM-DD,hh:mm');
var val1 = data.toString();
var val = val1.trim();
if (val == '') {
console.log('no data');
else {
console.log(val);
logger.write(dayTime + ',' + val + '\n');
}
});
});
Is it a problem with my codescode?
Thanks in advance.