Loosing network connection after less than a minute, why?

I am new to the Spark, seems like a great idea, but I’m getting really frustrated with it.

First issue, is it seems to try to reconnected to WiFi and Cloud (I guess?) after less than a minute of being powered on. My program runs for a short while then stops, the LED flashes cyan until it has reconnected, but the program does not function quite correctly afterwards.

My program is (aiming to) broadcast a UDP packet. This is the beginning, it will build up to more later, but for now this is it. This works, up until the issue described above. Once the apparent disconnect, reconnect happens, no more successful UDP packets are received by my other Windows program, even though the Spark appears to be functioning correctly (I see the serial comms and the D7 LED flash).

I have seen something about the cyan flash of death, but mine does reconnect.

Here is my code.

// UDP Port used for two way communication
unsigned int localPort = 6767;
IPAddress bcastip(255, 255, 255, 255);

// An UDP instance to let us send and receive packets over UDP
UDP Udp;

void setup()
{
    pinMode(D7, OUTPUT); // DEV BOARD LED
    
    Serial.begin(9600);
    digitalWrite(D7, HIGH);          // sets the LED on
    delay(5000);
    digitalWrite(D7, LOW);           // sets the LED off
    Serial.println("Serial begin");
    
    for (int i = 0; i < 10; i++)
    {
        digitalWrite(D7, HIGH);          // sets the LED on
        delay(50);                       // waits for 200mS
        digitalWrite(D7, LOW);           // sets the LED off
        delay(50);
    }
    
    delay(5000);
    
    for (int i = 0; i < 5; i++)
    {
        digitalWrite(D7, HIGH);          // sets the LED on
        delay(250);                       // waits for 200mS
        digitalWrite(D7, LOW);           // sets the LED off
        delay(250);
    }
    
    delay(5000);
    
    Serial.println("Starting UDP");
  // start the UDP
  Udp.begin(localPort);

  // Print your device IP Address via serial
  Serial.println(WiFi.localIP());
}

void loop()
{
    Serial.println("Broadcasting");
    Udp.beginPacket(bcastip, localPort);
    Udp.write("Hello");
    Udp.endPacket();
    digitalWrite(D7, HIGH);          // sets the LED on
    delay(250);                       // waits for 200mS
    digitalWrite(D7, LOW);           // sets the LED off
    delay(250);
    delay(2500);        
}

Since you are broadcasting, all hosts, including your own Spark core, are seeing your packets if they are looking for them. You need to read (and dump if you like) the received packets. If you don’t pick them up, the Ti CC3000 runs out of packet buffers and the core will reset. You could also set your local receive port to be different from your transmit port to avoid receiving them at all by changing the ports used for Udp.begin() and Udp.beginPacket().

Thanks for the reply and suggestion.

I ended up putting in the line;

Udp.stop();

after I had done the broadcast and moved the following line;

Udp.begin(localPort);

from the ‘setup’ to the start of ‘loop’. This seems to have made it stable.

For completeness and anyone looking for similar help, I also tried adding the line;

Udp.flush();

after performing the broadcast, this did not stop the core resetting.

I also had no success by adding the lines;

while (Udp.parsePacket() > 0)
{
    char c = Udp.read();
}

Hi @rob_f

You are still just masking the issue. Calling Udp.stop() will reset the socket and does throw away received data.

Udp.flush() just clears the software packet buffer but does not clear any data in the TI CC3000.

I think your read loop would work if you read more data at one time, rather than character by character. Udp.read(*buf, packet_length) is the form you want.

1 Like

Tried removing changing my method from Stop to reading the full buffer in one go as suggested, but it went straight back to the crashing situation again.