You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hello I'm trying to send data that is from serialport to client by SSE but, getting data from serialport is work and SSE(server-sent-events) is also work but, when I sent data that is from serialport that value was '' but console.log say has value '123.0g like this
this is my cord can you help me?
// @todo: This server should receives msgs from AMQPCloud
const { SerialPort, ReadlineParser } = require('serialport')
const port = new SerialPort({ path: 'COM5', baudRate: 2400 })
let str = '';
let weight = '';
port.on('readable', function () {
let a = port.read().toString('ascii');
str += a;
if (a === 'g') {
//console.log(str);
if (str.includes('WTST')) {
weight = str;
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
hello I'm trying to send data that is from serialport to client by SSE but, getting data from serialport is work and SSE(server-sent-events) is also work but, when I sent data that is from serialport that value was '' but console.log say has value '123.0g like this
this is my cord can you help me?
`
const express = require("express");
const cors = require("cors");
const liveStreamApp = express();
liveStreamApp.use(cors());
const clients = {};
// @todo: This server should receives msgs from AMQPCloud
const { SerialPort, ReadlineParser } = require('serialport')
const port = new SerialPort({ path: 'COM5', baudRate: 2400 })
let str = '';
let weight = '';
port.on('readable', function () {
let a = port.read().toString('ascii');
str += a;
if (a === 'g') {
//console.log(str);
if (str.includes('WTST')) {
weight = str;
})
liveStreamApp.get('/wallet', async (req, res) => {
const client = req.query.client;
clients[client] = res; // save response in memory
console.info(
Registered: ${client}
)// remove client when disconnect
res.socket.on('end', e => {
delete clients[client];
console.info(
Unregistered: ${client}
)res.end();
});
// accept SSE stream
res.setHeader("Content-Type", "text/event-stream");
// send welcome msg
res.write(
event: walletChange\n
);res.write(
data: Hello ${client}, you will receive updates when available...\n\n
);})
setInterval(_ => {
// send balance to registered clients every 10s || when needed
Object.keys(clients).forEach(client => {
console.log(
Sending msg to ${client}...
);clients[client].write(
event: walletChange\n
);//clients[client].write(
data: Your balance ${client}!\n\n
);//clients[client].write(
data:
+ weight);//clients[client].write(
data:
+ str);//console.log(weight);
})
}, 1500)
liveStreamApp.listen(1979, _ => console.info(
listening on 1979...
));`
Beta Was this translation helpful? Give feedback.
All reactions