Maintaining Publish/Subscribe connections

Turns out that I still have a problem with this. My test setup consistently locks up overnight (in the UK). I think the lockup is on the Publisher side but further testing is necessary to confirm this and to see whether there is any fixed (absolute or elapsed) time when this occurs. My test code has two sides - Publisher - Reader.

Spark1:

//Publisher - sends an incrementing value, as a string, every few seconds.
using namespace std;
bool ready;
unsigned long last;
int pubcount=0;
char publishString[10];

void setup() {
    Serial.begin(9600);
    
 Spark.variable("pubcount", &pubcount, INT); 
}

void loop() {
if (millis() - last > 5000) {
      sprintf(publishString, "%d", pubcount);
        Spark.publish("pubcount", publishString);
        pubcount++;
        last = millis();
  }
}

Spark2:

//Reader - receives published incrementing value and indicates status on Spark LED:
//  Yellow = stuck inside handler. Red/Green toggle on each new message
// Red/Green also flicker to indicate main loop is still running.
unsigned long lasttime;
int inval=0;
int lastval;
int ledstate=0;
int subscribed=0; //not used
const int flashtime=500;

void pubcountHandler(const char *event, const char *data){
    
RGB.color(0, 0, 255); //flag blue to indicate handler has been entered
inval=atoi(data);
if (inval != lastval){ //change led colour if new value received
    if (ledstate == HIGH) ledstate = LOW;
    else ledstate = HIGH;
    }
    lastval=inval;
} //end handler

void setup() {
//    Serial.begin(9600);
RGB.control(true);

Spark.variable("inval", &inval, INT); //make received value available for inspection
    
subscribed=Spark.subscribe("pubcount", pubcountHandler, "54ff71066672524839501267");

}//end setup

void loop() {
    //change colour to indicate handler is running
    
    //flash led to indicate main loop still running
    
        if (ledstate == HIGH)  {
            if (millis() - lasttime > flashtime) {
             lasttime=millis();
             RGB.color(255, 0, 0);
            }
            else RGB.color(64,0,0);
         }
         else {
            if (millis() - lasttime > flashtime) {
             lasttime=millis();
             RGB.color(0,255,0);
            }
            else  RGB.color(0,64,0);
         }
}

I would like to diagnose further by logging data through my Terminal overnight but a problem with the registration of my cores is preventing that for now.

Meanwhile I would appreciate any comments.