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;
}