Core dies after some time

Hi

After a while (approx. 6h) my core starts blinking green (WIFI_CONNECTING) and then Core is unable to reconnect. I know this is kind a hot topic and I am allready tried to patch CC3000 patches and try to update core firmwares every way but still no luck. Core dies after a time - seems like it drops WIFI connection but weird thing is that TCP dies a bit earlier than WIFI itself. Here is a short part of debug:

[WIFI] Connected
[SPARK] Connected
Time is: 1405990735
[TCP] sending: hello=true&time=1405990735
[TCP] status: 200
[WIFI] Connected
[SPARK] Connected
[WIFI] Connected
[SPARK] Connected
[WIFI] Connected
[SPARK] Connected
[WIFI] Connected
[SPARK] Connected
[WIFI] Connected
[SPARK] Connected
[WIFI] Connected
[SPARK] Connected
Time is: 1405990765
[TCP] send failed
[WIFI] Connected
[SPARK] Connected
Time is: 1405990845
[TCP] send failed
[WIFI] Connected
[SPARK] Connected
Time is: 1405990905
[TCP] send failed
[WIFI] Connected
[SPARK] Connected
Time is: 1405991025
[TCP] send failed
[WIFI] Disconnected
[WIFI] Trying to connect...

Here is loop function:

void loop(void)
{
	unsigned long now = millis();
	UNIXTIME = Time.now();
	
	// Check
	if(now - WIFI_status_time > 3000UL)
	{
		WIFI_status_time = now;

		// Connect to WIFI
		connectWIFI();
	}

    // Publish
if(now - lastPublishTime > (DATA_SYNC_TIME * 1000UL))
{
	lastPublishTime = now;

	// Send data
	// ... (Send TCP data)
}
}

And other relevant functions:

/* Connect to WIFI
 * 
 */
void connectWIFI()
{
	WIFI_status = WiFi.status();

	switch(WIFI_status)
	{
		case WIFI_OFF:
			status = false;
			if(DEBUG){
				Serial.println("[WIFI] Disconnected");
				Serial.println("[WIFI] Trying to connect...");
			}

			// Set WIFI ON
			WiFi.on();
		break;

		case WIFI_CONNECTING:
			status = false;
			if(DEBUG){
				Serial.println("[WIFI] Waiting for DHCP");
			}
		break;

		case WIFI_ON:
			if(DEBUG){
				Serial.println("[WIFI] Connected");
			}
			// Connect to Spark
			connectSPARK();
		break;
	}
}

/* Connect to Spark API
 * 
 */
void connectSPARK()
{
	SPARK_status = Spark.connected();

	if(!SPARK_status)
	{
		if(DEBUG){
			Serial.println("[SPARK] Connecting...");
		}
		
		// Connect to Spark API
		Spark.connect();
	}
	else
	{
		Serial.println("[SPARK] Connected");

		if(!status)
		{
			status = true;

			// Send connection info to server
			// ... (TCP data sending)
		}
	}
}

Also I can mention that I am using TCP client which sending after some time data to target server. Posted TCP client function also here:

/* HTTP Request to target server */
String POST(String controller, String post_data, bool sd_write)
{
    String response;
    
    if(status && client.connect(API_IP, API_PORT))
    {
        if(DEBUG)
        {
            Serial.print("[TCP] sent: ");
            Serial.println(post_data);
        }
        
        client.print("POST /v2/");

        client.print(controller);
        client.println("/ HTTP/1.1");
        
        client.print("Host: ");
        client.println(API_HOSTNAME);
        
        client.print("CORE_ID: ");
        client.println(SPARK_id);
        
        client.println("User-Agent: Client/1.0");
        client.println("Connection: close");
        client.println("Content-Type: application/x-www-form-urlencoded");
        
        client.print("Content-Length: ");
        client.print(post_data.length());
        client.print("\n\n");
 
        client.write((uint8_t*)post_data.c_str(), post_data.length());

        // Flush
        client.flush();
        
        while(!client.available());

        // Buffer placeholder
        char buffer[210];
        
        for(unsigned int i = 0; i < sizeof(buffer) && client.available(); i++)
        {
            // Read char
            char c = client.read();
            
            if(c == -1){
                break;
            }
            
            buffer[i] = c;
        }
        
        String str_response(buffer);

        int bodyPos = str_response.indexOf("\r\n\r\n");

        response = str_response.substring(bodyPos + 4);

        if(DEBUG){
            Serial.print("[TCP] recieved: ");
            Serial.println(response);
        }
        
    }
    else
    {
        if(DEBUG)
        {
            Serial.println("[TCP] send failed");
        }
        
        // Write missing data to SD card
        if(sd_write)
        {
            sdWrite(post_data);
        }
    }
    
    // Stop it
    client.stop();
    
    return response;
}

Hi @markopraakli,

Thanks for posting your code / a test case! I think its safe to say this probably shouldn’t happen. :slight_smile:

Just as a basic sanity check – Which version of the CC3000 patch did you apply? We’re rolling out an updated deep_update binary later today for those who haven’t patched, or to upgrade old versions of the patch. The latest firmwares should reset your core after a little while to get back online (if the wifi connection is failing, as a basic watchdog I think), and the latest patches fix some issues that could cause the cc3000 to drop offline / go mute in some circumstances. We also just recently found a bug in the host driver that was introduced a few months ago, that causes some packet of a given length to be misread.

Looking at the code, can you try throwing a short delay after your client.stop() call (like 5-50 ms)? I think there might be a socket cleanup issue there in the firmware, but I’m more of a server-side guy, so I might be wrong about that. :slight_smile:

Thanks,
David

Thanks for your reply.

I tried to use deep_update_2014_06 patch without success. Let’s hope that your new deep_update will be fix my problem.

But does delay(); function is blocking or non-blocking. Because I can not allow any blocking iterations in my code.

For all intents and purposes, delay() and delayMicroseconds() are considered blocking.

If the deep update doesn't seem to fix the problem, can you try using the delay() for temporary debug purposes? It can at least help to rule out some possibilities.