How to Display two String Array Esp8266 on data parser nodejs

Clash Royale CLAN TAG#URR8PPPHow to Display two String Array Esp8266 on data parser nodejs
I have data measured from ESP8266 which I store in a string array, and I display to my JavaScript HTML using Node.js, but I just get data as one array not as two array.
My Arduino code:
...
int temp1, hum1, temp2, hum2;
...
void setup(){
serial.begin(9600);
serial1.begin(115200);
...
}``
void loop(){
...
float t1 = bme1.readTemperature();
float h1 = bme1.readHumidity();
float t2 = bme2.readTemperature();
float h2 = bme2.readHumidity();
temp1 = t1;
hum1 = h1;
temp2 = t2;
hum2 = h2;
getStrings();
delay(3000);
...
}
void getStrings(){
String measure1=" "; String measure2=" ";
measure1 += temp1;
measure1 += " ";
measure1 += hum1;
measure1 += " ";
Serial.println(measure1);
measure2 += temp2;
measure2 += " ";
measure2 += hum2;
measure2 += " ";
Serial.println(measure2);
}
My serial monitor shows:
measure1: 12.34 23.45
measure2: 34.56 45.67
My Node.js code:
var exs = require('express');
var app = exs();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var port = require('serialport');
var parsers = port.parsers;
var parser = new parsers.Readline({delimiter:'n'});
var ports = new port("/dev/ttyUSB0", {baudRate:115200,parser:parser}, false);
process.setMaxListeners(Infinity);
ports.pipe(parser);
ports.on('open', function(){
console.log('portOpened');
io.on('connection', function(socket){
ports.on('data', function(data){
console.log('data: '+data);
parser.on('data', function(data){
var result = data.split(" ");
var temp-1 = result[1]
var hum-2 = result[2]
var temp-2 = result[3]
var hum-2 = result[4];
io.sockets.emit('update', {
tmp_1:temp-1.toString()+' *C',
hum_1:hum-1.toString()+' %',
tmp_2:temp-2.toString()+' *C',
hum_2:hum-2.toString()+' %'
});
});
});
});
});
...
When I call npm start, I just get all data as one array log:
npm start
data: 12.34 23.45 34.56 45.67
not a two array log as I want, like this:
string array 'measure1' as:
data1: 12.34 23.45
string array 'measure2' as:
data2: 34.56 45.67
Can anyone please help me?
on my arduino variable has string array of "measure-1" and "measure-2", and my nodejs to get a "measure" and store to argument function javascript "data", =>> parser.on('data', function(data){}. but the result "measure-1" and "measure-2" as one array on my console.log, i don/t know how to string array "measure-1" as some "data-1" and string array "measure-2" as some "data-2"???
– abu-ahmed al-khatiri
Jul 24 at 5:48
Try to send it in an object like this { measure-1: « blabla », measure-2: « some data » } it’ll be much easier to parse
– menett_a
2 days ago
what there into socket emit, Sir?. my first step i want to store "measure" to console as two data array, and then i can store two data array to socket.emit ..
– abu-ahmed al-khatiri
6 hours ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What do you mean by two array log ? Give me an example please
– menett_a
Jul 23 at 12:36