I am trying to write program code to make my datalogger (CR1000X) send data to my NodeJS server, here is my server code:
const net = require('net');
// Tạo server TCP
const server = net.createServer((socket) => {
console.log('Client connected:', socket.remoteAddress, socket.remotePort);
socket.on('data', (data) => {
console.log('Hex Data:', data.toString('utf-8'));
});
socket.on('end', () => {
console.log('Client disconnected');
});
socket.on('error', error => {
console.log('Client disconnected', error);
});
});
const PORT = 6785;
server.listen(PORT, () => {
console.log(`Server is listening on port ${PORT}`);
});
It’s just simple to get the data from the datalogger. But sometimes, I saw the log Client disconnected
:
Client disconnected Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:216:20) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read'
}
but I dont know how to solve this on datalogger size, here is my CRBasic code:
BeginProg
Socket = TCPOpen(IP_Addr,PORT,3)
CPISpeed(250) '250 kbps, how fast the datalogger will operate the CPI bus.
'This value may need to be adjusted based on the number of
'VWIRE 305 modules and the total cable length. Refer to the
'VWIRE 305 quick start guide for more information.
Scan(5, msec, 500, 0) '200 Hz / 5 msec scan rate
CDM_VW300Dynamic(CPIAddress, Freq(), Diag()) 'Get dynamic readings
CallTable DynamicFreq
If TimeIntoInterval(0,1,Sec) Then ' Process static data only once per second
CDM_VW300Static(CPIAddress, StaticFreq(), Therm(), DynStdDev()) 'Get static data
CallTable OneSecData
OutString = FormatFloat(Freq(1), "%f")
OutString = OutString & "," & FormatFloat (Freq(2), "%f")
For i = 1 To 2
OutString = OutString & "," & FormatFloat (Therm(i), "%f")
Next
If Socket > 0 Then
SerialOut(Socket, OutString, 0, 1, 0)
End If
EndIf
NextScan
EndProg
My purpose is catch socket problem/error on CRBasic, then connect again + send data
I tried to search on CRBasic site, but I can not find the way to solved this
Dung Do is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
4