Problems with serial over time

Hi guys,
I’m having a problem with serial over time. I have a TCP/IP app running, which is sending serial data if it gets a message from the other side. The TCP/IP is working fine, however, it seems that after approximately two hours, the TCP/IP app stops sending serial into the Arduino. I see this clearly because the TX/RX lights on the Arduino no longer light up.

This is my code: Help would be amazing. I’ve been ripping my hair off for the last 2 days.

#include “testApp.h”

#define RECONNECT_TIME 400

//--------------------------------------------------------------
void testApp::setup(){

ofSetFrameRate(60);
ofBackground(0);
ofSetLogLevel(OF_LOG_NOTICE);
ofSetVerticalSync(true);
ofEnableSmoothing();

serial.close();
serial.flush(true);
serial.listDevices();
vector deviceList = serial.getDeviceList();
serial.setup(5, 57600); //open the first device
typed = false;
pos = 0;
msgTx = “”;
msgRx = “”;
weConnected = tcpClient.setup(“127.0.0.1”, 11999);
tcpClient.setMessageDelimiter("\n");

connectTime = 0;
deltaTime = 0;

tcpClient.setVerbose(true);

}

//--------------------------------------------------------------
void testApp::update(){

if(weConnected){
if(tcpClient.send(msgTx)){
msgRx = tcpClient.receive();
if( msgRx.length() > 0 ){
lastMsg = msgRx;
serial.writeBytes((unsigned char*)msgRx.c_str(), 2);
}
}else if(!tcpClient.isConnected()){
weConnected = false;
}
}else{
deltaTime = ofGetElapsedTimeMillis() - connectTime;
if( deltaTime > 5000 ){
weConnected = tcpClient.setup(“127.0.0.1”, 11999);
connectTime = ofGetElapsedTimeMillis();
}
}
}

//--------------------------------------------------------------
void testApp::draw(){
ofBackground(230, 230, 230);
ofSetColor(20, 20, 20);
ofDrawBitmapString(“openFrameworks TCP Send Example”, 15, 30);
if(typed){
ofDrawBitmapString(“sending:”, 15, 55);
ofDrawBitmapString(msgTx, 85, 55);
}
else{
if(weConnected)ofDrawBitmapString(“status: type something to send data to port 11999”, 15, 55);
else ofDrawBitmapString(“status: server not found. launch server app and check ports!\n\nreconnecting in “+ofToString( (5000 - deltaTime) / 1000 )+” seconds”, 15, 55);
}
ofDrawBitmapString(“from server: \n”+lastMsg, 15, 270);
for (int i = 0; i < 6; i++) {
if (i % 2 == 0) ofSetColor(255);
else ofSetColor(255,0,0);

if(lastMsg == “u”+ofToString(i)) ofCircle(50*(i+1), 90, 20);
if(lastMsg == “d”+ofToString(i)) ofCircle(50*(i+1), 140, 20);
}
}

Any solving ideas ?
I have been reading this problem , and also meet it. I am on my way to take haire from my head also.

Sudden stop of sening data after a presumed 6, 7 hours appears in my case too, and arduino works except this data does not come on the serial.

Help.

i had that problem too.

if i remember right dealt with the problem by telling the arduino to reset itself if it did not get any serialIn for x amount of time.

I am having a similar problem. Happens between 1 and 2 hours. Wondering if I need to flush the serial every so often? What is the max the serial buffer can hold? Is there a way to query it? A least knowing these question will help to know if I am barking up the right tree or not…