Hi All,
The forums have been of great help till date.
I am working on a small project where I am sampling data from sensors and the readings are saved in a file in SD Card. I am writing to csv file. I want to upload these files from SD Card to backend server once in a day.
I found many forums explaining to upload image file/ text file. But in all of these discussions, they open the file, read byte by byte from file and send data to the backend. This works but is very slow. Is there any other way? As of what I know, it can be done in two possible ways.
- HTTP POST command. I have to divide file into multiple requests and send. I do not want to do this.
- FTP - I have no idea how to do this.
Please help me out with this. I believe that there should be better solution to this problem.
Hi,
I'm working in some very close to this and didn't found a solution to "upload" files. I also have other problem, the SD have a high performance on consumption terms. What module are you using? Do you have this on a place with out electricity?
I think that we are working in similars thing and probably we could help together if we obtain certain innovation.
Code that speeds up SD file uploading.
//zoomkat 12/26/12
//SD server test code
//open serial monitor to see what the arduino receives
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = {
192, 168, 1, 102 }; // ip in lan
byte gateway[] = {
192, 168, 1, 1 }; // internet access via router
byte subnet[] = {
255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
String readString;
//////////////////////
void setup(){
Serial.begin(9600);
// disable w5100 while setting up SD
pinMode(10,OUTPUT);
digitalWrite(10,HIGH);
Serial.print("Starting SD..");
if(!SD.begin(4)) Serial.println("failed");
else Serial.println("ok");
Ethernet.begin(mac, ip, gateway, gateway, subnet);
//delay(2000);
server.begin();
Serial.println("Ready");
}
void loop(){
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
//client.println("Content-Type: text/html");
client.println("Content-Type: image/jpeg");
//client.println("Content-Type: image/gif");
//client.println("Content-Type: application/x-javascript");
//client.println("Content-Type: text");
client.println();
//File myFile = SD.open("boom.htm");
File myFile = SD.open("HYPNO.JPG");
//File myFile = SD.open("BLUEH_SL.GIF");
//File myFile = SD.open("SERVOSLD.HTM");
if (myFile) {
byte clientBuf[64];
int clientCount = 0;
while(myFile.available())
{
clientBuf[clientCount] = myFile.read();
clientCount++;
if(clientCount > 63)
{
// Serial.println("Packet");
client.write(clientBuf,64);
clientCount = 0;
}
}
//final <64 byte cleanup packet
if(clientCount > 0) client.write(clientBuf,clientCount);
// close the file:
myFile.close();
}
delay(1);
//stopping client
client.stop();
readString="";
}
}
}
}
}
I dont know if arduino is capable of ftp uploading, but this is the fastest solution I imagine. Ftp just transfers the entire .csv and then the backend server can open it and load all the data very fast.
mart256:
I dont know if arduino is capable of ftp uploading, but this is the fastest solution I imagine. Ftp just transfers the entire .csv and then the backend server can open it and load all the data very fast.
Yes it is. The ethernet shield does fine at FTP, but the wifi shield can't.
http://playground.arduino.cc/Code/FTP