So I've managed to get my shield up and running, doing post request with basic http authentication. Everything works great. However, I realized my unit is crashing after 1 successful call to my server. So i started digging deeper:
Code: Select all
void postPointToServer(String data) {
Serial.print("postPointToServer:");
Serial.println(data);
// Http Basic Authorization
String auth_raw = serial + ":" + token;
char auth_input[200];
char auth_output[200];
auth_raw.toCharArray(auth_input, auth_raw.length() + 1);
base64_encode(auth_output, auth_input, auth_raw.length());
Serial.println("1");
Adafruit_CC3000_Client www = cc3000.connectTCP(ip, PORT);
if (www.connected()) {
www.fastrprint(F("POST ")); www.fastrprint(WEBPAGE); www.fastrprint(F(" HTTP/1.1\r\n"));
www.fastrprint(F("Host: ")); www.fastrprint(WEBSITE); www.fastrprint(F("\r\n"));
www.fastrprint(F("Authorization: Basic ")); www.fastrprint(auth_output); www.fastrprint(F("\r\n"));
www.fastrprint(F("Content-Type: application/x-www-form-urlencoded")); www.fastrprint(F("\r\n"));
char len_c[7];
itoa(data.length(), len_c, 10);
www.fastrprint(F("Content-Length: ")); www.fastrprint(len_c); www.fastrprint(F("\r\n"));
// Extra empty line for post arguments
www.fastrprint(F("\r\n"));
char data_c[200];
data.toCharArray(data_c, data.length() + 1);
www.fastrprint(data_c); www.fastrprint(F("\r\n"));
www.fastrprint(F("\r\n"));
www.println();
displayGreen();
Serial.println("2");
} else {
Serial.println(F("Connection failed"));
displayRed();
www.close();
return;
}
/* Read data until either the connection is closed, or the idle timeout is reached. */
/*
unsigned long lastRead = millis();
while (www.connected() && (millis() - lastRead < IDLE_TIMEOUT_MS)) {
while (www.available()) {
char c = www.read();
Serial.print(c);
lastRead = millis();
}
}
*/
Serial.println("3");
www.close();
Serial.println("4");
}
And this is what comes out in my serial.monitor:
Code: Select all
Free RAM: 6577
Initialization Complete
Wireless Connected!
DHCP Requested!
Setup Complete
getEC:*OK
getPH:3.36
postPointToServer:ec=*OK&ph=3.36
1
2
3
Can an expert shed some light on this issue?