I understand the serial.write bit, and I know that the 0x1A means end of data, but what do the two following lines mean?
So thats the question above. Now for a description?
Basically using the 3g shield I'm planning on sending data to a FTP server. The section I'm confused by is the bit where the text file is created then sent. Three bytes are being sent, one i know is the end of data byte... what are the other two? Error checking? but doesn't that change depending on whats in the data?
I got the code from Cooking Hacks page : http://www.cooking-hacks.com/index.php/documentation/tutorials/arduino-3g-gprs-gsm-gps
Serial.println("01234567890123456789"); //Data for the file
Serial.write(0x1A); //End of Data
Serial.write(0x0D);
Serial.write(0x0A);
from this:
int led = 13;
int onModulePin = 2; // the pin to switch on the module (without press on button)
char data[1024];
int x=0;
int file_size;
char server[ ]="";
char port[ ]="";
char user_name[ ]="";
char password[ ]="";
void switchModule(){
digitalWrite(onModulePin,HIGH);
delay(2000);
digitalWrite(onModulePin,LOW);
}
void setup(){
Serial.begin(115200); // UART baud rate
delay(2000);
pinMode(led, OUTPUT);
pinMode(onModulePin, OUTPUT);
switchModule(); // switches the module ON
for (int i=0;i< 5;i++){
delay(5000);
}
Serial.println("AT+CGSOCKCONT=1,\"IP\",\"myapn\"");
Serial.flush();
x=0;
do{
while(Serial.available()==0);
data[x]=Serial.read();
x++;
}while(!(data[x-1]=='K'&&data[x-2]=='O'));
}
void loop()
{
Serial.print("AT+CFTPSERV=\""); //Sets the FTP server
Serial.print(server);
Serial.println("\"");
Serial.flush();
x=0;
do{
while(Serial.available()==0);
data[x]=Serial.read();
x++;
}while(!(data[x-1]=='K'&&data[x-2]=='O'));
Serial.print("AT+CFTPPORT="); //Sets FTP port
Serial.println(port);
Serial.flush();
x=0;
do{
while(Serial.available()==0);
data[x]=Serial.read();
x++;
}while(!(data[x-1]=='K'&&data[x-2]=='O'));
Serial.print("AT+CFTPUN=\""); //Sets the user name
Serial.print(user_name);
Serial.println("\"");
Serial.flush();
x=0;
do{
while(Serial.available()==0);
data[x]=Serial.read();
x++;
}while(!(data[x-1]=='K'&&data[x-2]=='O'));
Serial.print("AT+CFTPPW=\""); //Sets password
Serial.print(password);
Serial.println("\"");
Serial.flush();
x=0;
do{
while(Serial.available()==0);
data[x]=Serial.read();
x++;
}while(!(data[x-1]=='K'&&data[x-2]=='O'));
Serial.println("AT+CFTPMODE=1"); //Selects pasive mode
Serial.flush();
x=0;
do{
while(Serial.available()==0);
data[x]=Serial.read();
x++;
}while(!(data[x-1]=='K'&&data[x-2]=='O'));
Serial.println("AT+CFTPTYPE=A"); //Selects ASCII mode
Serial.flush();
x=0;
do{
while(Serial.available()==0);
data[x]=Serial.read();
x++;
}while(!(data[x-1]=='K'&&data[x-2]=='O'));
Serial.println("AT+CFTPPUT=\"/test.txt\""); //Creates a file and sends data (ASCII)
Serial.flush();
while(Serial.read()!='N'); //Waits 'N' from BEGIN
Serial.println("01234567890123456789"); //Data for the file
Serial.write(0x1A); //End of Data //EOL character
Serial.write(0x0D);
Serial.write(0x0A);
x=0;
do{
while(Serial.available()==0);
data[x]=Serial.read();
x++;
}while(!(data[x-1]=='K'&&data[x-2]=='O'));
delay(1000);
Serial.println("AT+CFTPGET=\"/test.txt\""); //Reads the data from test file
Serial.flush();
x=0;
do{
while(Serial.available()==0);
data[x]=Serial.read();
x++;
}while((data[x-1]!=','));
x=0;
while(Serial.peek()!=0x0A){
file_size=(file_size*10)+(Serial.read()-0x30);
};
for(x=0;x< file_size;x++){
while(Serial.available()==0);
data[x]=Serial.read();
}
Serial.print(data);
while(1);
}
Moderator edit: Marked thread solved. (Nick Gammon)