Then I upload them to server ( I'm using a simple server script in my personal computer to save the data as txt). The problem is; Stored data is about 4MBytes on the server side and transferring this data takes about 10-11 minutes per try. Is there a way to improve upload time?
Here is my http post code;
Code: Select all
int postJsonData(char * ret_serverResponse, int16_t * xbuffer, int16_t * ybuffer, int16_t * zbuffer, const char * inp_hostname, const uint16_t inp_port, char * inp_endPoint,WiFiClient client)
{
if(client.connect(inp_hostname,inp_port))
{
char headers[255]={0};
sprintf(headers,"{\"Sensor_Type\":\"Sensor\",\"Sensor_Sensitivity\":%u,\"Measure_Periud_us\":%u,\"Measurement_Count\":%lu,",MEASUREMENT_SENSITIVITY,MEASURE_PERIOD_US,MEASURE_COUNT);
char xheader[]="\"XARRAY\":[";
char yheader[]="\"YARRAY\":[";
char zheader[]="\"ZARRAY\":[";
uint32_t datasize=0;
for (uint32_t i=0;i<MEASURE_COUNT;i++)
{
datasize=datasize+String(xbuffer[i]).length()+String(ybuffer[i]).length()+String(zbuffer[i]).length();
}
// Sending "POST command to endpoint
client.print("POST ");
client.print(inp_endPoint);
client.print(" HTTP/1.1\r\n");
// Sending HTTP headers
client.print("Host: ");
client.print(inp_hostname);
client.print("\r\n");
client.print("Connection: close\r\n");
client.print("Content-Length: ");
client.print(strlen(headers)+strlen(xheader)+strlen(yheader)+strlen(zheader)+datasize+(MEASURE_COUNT*3)+9);
//
client.print("\r\n");
client.print("Content-Type: text/plain\r\n\r\n");
// Sending headers and post together
// Sending data
client.print(headers);
client.print(xheader);
for(uint32_t i=0;i<MEASURE_COUNT;i++)
{
client.printf("%d,",xbuffer[i]);
}
client.printf("0],");
client.print(yheader);
for(uint32_t i=0;i<MEASURE_COUNT;i++)
{
client.printf("%d,",ybuffer[i]);
}
client.printf("0],");
client.print(zheader);
for(uint32_t i=0;i<MEASURE_COUNT;i++)
{
client.printf("%d,",zbuffer[i]);
}
client.printf("0]}");
client.print("\r\n");
unsigned long timeout = millis();
// Get Client Response
while (client.available() == 0){
if (millis() - timeout > 3000){
Serial.println(">>> Client Timeout !");
client.stop();
return -2;
}
}
strcat(ret_serverResponse,(client.readStringUntil('\r')).c_str());
client.stop();
return parseHttpCode(ret_serverResponse);
}
else
{
Serial.println("Cannot connect to the host");
return -1;
}
}