Red flashing after trying to connect

Ok, so I have a large program which I am compiling locally. The code includes both TCPServer and UDP instances, the latter to fetch ntp time using the SparkTime libary. If I include these statements with NO other code referring to these instances:

UDP UDPClient;

TCPServer server = TCPServer(80);

Everything compiles, I lode the code via USB and it will go to flashing green, then flashing red, then flashing cyan and start back at green. If I remove either or both of the statements, everything works fine, it connects to the cloud and the rest of the code runs!

So possible conclusions are: a) You can’t have TCPServer and UPD at the same time or b) Som’tin ain’t right in Kansas Toto!

Comments please.

Hi @peekay123,

I think there is a parallel discussion right not about recent firmware changes causing the default firmware build to use too much ram, so I'm guessing you're running out of ram. I think they're working on fixing this

Thanks!
David

Aha!! So we aren’t in Kansas anymore! I was hoping that was not the issue but it’s impossible to predict RAM usage when a lot it is dynamically allocated. Thanks Dave!! :smile:

1 Like

Let my simple mind do some walking.

Novice Suggested Solution:

  1. Local Only Core Firmware --> More Room --> Testing

  2. Cloud Connected Core --> In Project with Finally optimized Functional Code

Just an idea.

Hi @peekay123, what do you think might be the problem if I’m having the same red led after trying to flash BUT, I don’t have any UDP or TCP server clients in my code? It compiles fine and the code itself worked fine even yesterday. I tried to add extra components, then the red flashing happened- took it out, but it’s still flashing red when I try to download it… Wondering if I can get your input on this. Thanks!

@jkkim93, did you do a factory reset before trying the code again without the extra stuff. The red flashing will prevent OTA programming from working so either you program over USB or factory reset your Core so it can be reflashed again. :smile:

BTW, which extra “components” were you trying to add?

2 Likes

Everytime it does crash, I’ve been doing a factory reset- I was trying to add a modulus operator to an if statement so that the boolean returns true when the variable is a multiple of 5. I know the % sign works as one in regular syntax and thought it was the same in the sparkcore- any comments? Thank you!!!

@jkkim93, I would need to see your code to be able to help :smile:

1 Like

Thank you so much! I’m 99.9% sure I didn’t touch the code since its last state until I tried adding somethings, but the new additions are commented out…

char publishString3[40];
int i=0;
int j=0;
int a = 0;

const int strokeButton = 1;
const int blitz = 7;
int strokeCount = 0;
int stroke = 0;
int lastButtonState = 0;

unsigned publishTime[600];
unsigned publishCount[600];
//unsigned publishEndTime[600];
unsigned currentTime;
char publishStrokeCount[64];
//char publishEndTimeString[64];

unsigned long lastTime2 = 0UL;
unsigned long lastTime3 = 0UL;

int state = LOW;

//----------------------------------------------------------------------------

void setup() {  
    Time.zone(-4);
    pinMode(strokeButton, INPUT);
  pinMode(blitz, OUTPUT);

 Spark.function("grabit", grabData);

}

//----------------------------------------------------------------------------

void loop() {

stroke = digitalRead(strokeButton);
if(stroke != lastButtonState) {
    if(stroke == HIGH) {
        strokeCount++;
        currentTime = Time.now();
        publishTime[j] = millis();
        publishCount[j] = strokeCount;
        digitalWrite(blitz,HIGH);

        //if(strokeCount % 5 == 0) {
        //    if(publishCount[j] - publishCount[j-5] >= 30000UL) {
        //        publishEndTime[j] = currentTime;
        //    }
        //}

        if(j==599) {
            j=0;
        }

        else {
        j++;
        }
    }
}
else {
    digitalWrite(blitz, LOW);
}

lastButtonState = stroke;

//----------------------------------------------------------------------------
unsigned long now3 = millis();

if (now3-lastTime3>1000UL) {                        //every second, prints out one index at a time
        lastTime3 = now3;

    if(state == HIGH && i <= strokeCount){
        sprintf(publishString3,"%u",publishTime[i]);
        sprintf(publishStrokeCount, "%u", publishCount[i]);
        //sprintf(publishEndTimeString, "%u", publishEndTime[i]);
        if(i==599) {
            state = LOW;
            i=0;
        }
        Spark.publish("Uptime", publishString3);
        Spark.publish("stroke", publishStrokeCount);
        //Spark.publish("end", publishEndTimeString);
        i++;
        }
    }
}
//----------------------------------------------------------------------------
//This section is not in the loop
int grabData(String args) {
     if (state == HIGH){
    state = LOW;
    i=0;
  } else {
    state = HIGH;
  }
return state;
}

@bko thank you as well!!!

Well I tried to debug this tonight but it is confusing. There is a hard fault (single red led flash in the middle of two SOS flashes). It happens very early in the startup–before setup() since I added some Serial prints there and in loop() but get nothing.

I thought it must be related to the Spark.publish() or Spark.function() code, but commenting those out made no difference. There are a lot of types that are not-quite-rigth but still compile.

Maybe a fresh set of eyes will see–it must be right in front of my nose!

@bko, I addressed this issue in response to a PM sent to me by @jkkim93!

In short, the problem is due the very large arrays being declared. :smile:

1 Like

change to:

unsigned long publishTime[600];
unsigned long publishCount[600];
//unsigned long publishEndTime[600];
unsigned long currentTime;

Might help?

1 Like

@BDub, thanks for the input- sadly, I was hoping the solution would be as simple as assigning it a long, but still getting my one red flash error with it. Just out of curiosity though, what is the difference between saying simply “unsigned” versus unsigned then a specific data type?
thanks for the inputs @peekay123 and @bko, I’ll play around with the byte size and hopefully it’ll work! You guys rock. Update: reducing the byte size even by a little solves the problem. I guess I was stretching the core’s memory limits

1 Like

just out of curiosity, how did you debug it line by line? I know I can do the console on the java side to debug that, but haven’t been able to find a way to see the code execute line by line on the core side- did you just serial print something at each code block to see if executed that section? Thanks a ton @bko!

Hi @jkkim93

I did this:

void loop() {
  Serial1.print("2");
stroke = digitalRead(strokeButton);
  Serial1.print("3");
if(stroke != lastButtonState) {
      Serial1.print("A");
    if(stroke == HIGH) {
  Serial1.print("B");
        strokeCount++;

I was using Serial1 on a display but Serial to a USB host would be good too.

2 Likes