hello
i need your help,
im trying to transfer csv file from dfrobot sd card to a ftp server using GSM shield sim5216A.
my reference is http://www.cooking-hacks.com/documentation/tutorials/arduino-3g-gprs-gsm-gps#step13 the code is only explaining how to transfer a file from local storage to FTP server and nothing is said about the SD card. I added the SD card initialization code and opened the text file in read mode. After this I don't know How I am supposed to proceed. here is my code,
#include <SD.h>
const int chipSelect = 10;
int8_t answer;
int onModulePin= 2;
char aux_str[50];
char file_name[]="datalog.csv";
File dataFile = SD.open(file_name, FILE_READ);
void setup(){
delay(5000);
Serial.begin(115200);
pinMode(chipSelect, OUTPUT);
pinMode(10, OUTPUT);
digitalWrite(10,HIGH);
Serial.print("Menginisialisasi kartu SD...");
if (!SD.begin(chipSelect))
{
Serial.println("Kartu tidak tersedia");
return;
}
Serial.println("Inisialisasi Sukses. Kartu tersedia");
dataFile = SD.open(file_name);
if (dataFile){
Serial.println(" datalog.csv dibuka dalam posisi membaca.");
power_on();
Serial.println("GSM modem working!");
delay(3000);
// waits for signal
while( (sendATcommand("AT+CREG?", "+CREG: 0,1", 500) ||
sendATcommand("AT+CREG?", "+CREG: 0,5", 500)) == 0 );
// sets APN, user name and password
answer=sendATcommand("AT+CGSOCKCONT=1,\"IP\",\"internet\"", "OK", 2000);
Serial.println(answer);
answer=sendATcommand("AT+CSOCKAUTH=1,0,\"user_name\",\"password\"", "OK", 2000);
Serial.println(answer);
answer=sendATcommand("AT+CFTPUN=\"myusername\"", "OK", 2000);
Serial.println(answer);
answer=sendATcommand("AT+CFTPPW=\"mypassword\"", "OK", 2000);
Serial.println(answer);
// sets the paremeters for the FTP server and the path
answer=sendATcommand("AT+CFTPSERV=\"myserver.com\"", "OK", 2000);
Serial.println(answer);
//String ftp = "AT+CFTPPUTFILE=";
//answer=sendATcommand("AT+CFTPPUTFILE="dataFile, "OK", 2000);
sprintf(aux_str, "AT+CFTPPUTFILE=\"%s\",0", file_name);
answer = sendATcommand(aux_str, "+CFTPPUTFILE: 0", 6000);
Serial.println(answer);
if (answer == 1)
{
Serial.println("Upload done");
}
else
{
Serial.println("Upload fail");
}
}
//sendATcommand("AT", "OK", 5000);
}
void loop()
{
}
void power_on(){
uint8_t answer=0;
// checks if the module is started
answer = sendATcommand("AT", "OK", 2000);
if (answer == 0)
{
// power on pulse
digitalWrite(onModulePin,HIGH);
delay(3000);
digitalWrite(onModulePin,LOW);
// waits for an answer from the module
while(answer == 0){
// Send AT every two seconds and wait for the answer
answer = sendATcommand("AT", "OK", 2000);
}
}
}
int8_t sendATcommand(char* ATcommand, char* expected_answer1,
unsigned int timeout)
{
uint8_t x=0, answer=0;
char response[100];
unsigned long previous;
memset(response, '\0', 100); // Initialize the string
delay(100);
while( Serial.available() > 0) Serial.read(); // Clean the input buffer
Serial.println(ATcommand); // Send the AT command
x = 0;
previous = millis();
// this loop waits for the answer
do{
if(Serial.available() != 0){
response[x] = Serial.read();
x++;
// check if the desired answer is in the response of the module
if (strstr(response, expected_answer1) != NULL)
{
answer = 1;
}
}
// Waits for the asnwer with time out
}while((answer == 0) && ((millis() - previous) < timeout));
return answer;
}
and this is the out put I am getting.
Menginisialisasi kartu SD...Inisialisasi Sukses. Kartu tersedia
datalog.csv dibuka dalam posisi membaca.
AT
GSM modem working!
AT+CREG?
AT+CGSOCKCONT=1,"IP","internet"
1
AT+CSOCKAUTH=1,0,"user_name","password"
0
AT+CFTPUN="myusername"
1
AT+CFTPPW="mypassword"
1
AT+CFTPSERV="myserver.com"
1
AT+CFTPPUTFILE="datalog.csv",1
0
Upload fail
please help me,
and thank you very much.