Pages: [1]   Go Down
Author Topic: GPRS SHIELD EMAIL attachment problem  (Read 1067 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using Seeed studio GPRS shield and ARDUINO mega 2560, SD card to store the climatic data.I wanted to attach the climatic data when it reaches fixed amount of size(ex.50 kb).I am using the following code. I am able to attach a size of 1 kb and unable to attach file with more than 1 kb. can somebody suggest me where have I made the mistake........

Code:
declarations
setup()
loop()
{
  temperature_humidity();                     // gets the temperature and humidity values
  light_intensity();                         // gets light intensity
  dust_value();                             // gets dust in environment
  tosd_card();                             // stores in SD card in file CLIMATIC.txt
  myFile = SD.open("climatic.txt");
  unsigned long amount=myFile.size();
  myFile.close();
  Serial.println(amount);
  if(amount > 51200)
    {
        attachment_sending();
    }
}


void attachment_sending()
{
    delay(5000);  
    Serial.println("AT+CIPSTART=\"TCP\",\"xxxxxxxxxxxx\",\"25\"");  //gprs initialisation is done in the setup
   delay(7000);
   char h[]="helo xxxx@online.de";
   senddata(h);
   char a[]="AUTH LOGIN";
   senddata(a);
   char u[]="V2uhgdrtg";
   senddata(u);
   char p[]="Vfgjkgfkjg";
   senddata(p);
   char mf[]="MAIL FROM:<xxxxxxxxxx@online.de>";
   senddata(mf);
   char mt[]="RCPT TO:<xxxxxxxxxxx@xxxx.COM>";
   senddata(mt);
   char dt[]="DATA";
   senddata(dt);
   Serial.println("AT+CIPSEND");//begin send data to remote server
   delay(4000);
   Serial.println("FROM:<xxxxxxxxxxxxx@online.de>");
   delay(1000);
   Serial.println("TO:<xxxxxxxxxx@xxxxx.COM>");
   delay(1000);
   Serial.println("subject:xxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
   delay(1000);
   Serial.println("MIME-Version: 1.0");
   delay(100);
   Serial.println("CONTENT-TYPE: multipart/mixed; boundary=\"three\"");
   delay(100);
   Serial.println("--three");
   delay(100);
   Serial.println("Content-Type: multipart/alternative; boundary=\"one\"");
   delay(100);
   Serial.println("--one");
   delay(100);
   Serial.println("Content-Type: text/plain; charset=ISO-8859-1");
   delay(100);
   Serial.println("--one");
   delay(100);
   Serial.println("Content-Type: text/html; charset=ISO-8859-1");
   delay(100);
   Serial.println("Content-Transfer-Encoding: quoted-printable");
   delay(100);
   Serial.println("<p>=A0</p>");
   delay(100);
   Serial.println("--one--");
   delay(100);
   Serial.println("--three");
   delay(100);
   Serial.println("--three");
   delay(100);
   myFile = SD.open("climatic.txt",FILE_READ);
   delay(100);
   Serial.println("CONTENT-TYPE: TEXT/PLAIN; charset=US-ASCII; name=CLIMATIC.TXT");
   delay(100);
   Serial.println("CONTENT-DISPOSITION: ATTACHMENT; FILENAME=CLIMATIC.TXT");
   delay(100);
   Serial.println("CONTENT-TRANSFER-ENCODING: base64 ");
   Serial.println("");
   delay(200);
   encode();
   delay(100);
   Serial.println("--three--");
   delay(100);
   Serial.println(".");
   delay(100);
   Serial.println(".");
   delay(100);
   Serial.println((char)26);
   delay(20000);
   myFile.close();
   SD.remove("climatic.txt");
}



void encodeblock(unsigned char in[3],unsigned char out[4],int len)
 {
     out[0]=cb64[in[0]>>2];
     out[1]=cb64[((in[0]&0x03)<<4)|((in[1]&0xF0)>>4)];
     out[2]=(unsigned char) (len>1 ? cb64[((in[1]&0x0F)<<2)|((in[2]&0xC0)>>6)] : '=');
     out[3]=(unsigned char) (len>2 ? cb64[in[2]&0x3F] : '=');
}
void encode()
{
    unsigned char in[3],out[4];
    int i,len,blocksout=0;
    while (myFile.available()!=0)
      {
          len=0;
          for (i=0;i<3;i++)
             {
                   in[i]=(unsigned char) myFile.read();
                   if (myFile.available()!=0)
                       len++;
                   else
                       in[i]=0;
             }
         if (len)
           {
              encodeblock(in,out,len);
              for(i=0;i<4;i++)
              Serial.write(out[i]);
              blocksout++;
           }
         if (blocksout>=19||myFile.available()==0)
          {
            if (blocksout) Serial.print("\r\n");
            blocksout=0;
          }
      }
}

void senddata(char c[])
{
   Serial.println("AT+CIPSEND");//begin send data to remote server
   delay(100);
   Serial.println(c);
   delay(100);
   Serial.println((char)26);
   for(int i=0;i<15;i++)
     {
        delay(1000);
     }
}
« Last Edit: March 08, 2013, 06:25:53 am by bhaskar » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46042
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
can somebody suggest me where have I made the mistake........
Which one? Not reading the sticky at the top of the forum that describes how to post code? Or the one where you posted your code incorrectly?

Your code doesn't really look like that, does it?

Before you fix your post, though, fix the code. Use Tools + Auto Format to properly indent it, before you try posting it again.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46042
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What is important here is solving the problem in attaching file with size greater than 1 kb
What is important is being able to read the code you are actually using. Until we can do that, we can't help you.

Although I don't suppose we will anyway. I suspect that the limit is imposed by your carrier, not the hardware or software.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I suspect that the limit is imposed by your carrier, not the hardware or software.

you mean network carrier? I am using o2 and it supports 20 mb size attachment.
Logged

Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Since you send everything to Serial you should be able to see the messages and replicate the session with your smtp server, using putty or telnet or whatever network terminal on port 25. That would make things easier. As for what can be wrong with your code, it seems to me that sending the cr-lf sequence at the end of the attachment and before the part boundary (--three--) is a matter of chance. It seems that the file size should be divisible by three, but I may be in error myself. Anyway, you may add a cr-lf (or Serial.println()) in attachment_sending() right after invoking encode(), just to rule out this possibility.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
it seems to me that sending the cr-lf sequence at the end of the attachment and before the part boundary (--three--) is a matter of chance. It seems that the file size should be divisible by three, but I may be in error myself. Anyway, you may add a cr-lf (or Serial.println()) in attachment_sending() right after invoking encode(), just to rule out this possibility.

I am able to send attachment if reduce the file size(variable amount in code) to 1024 bytes, and its not working for higher size. Anyway I tried with changes made in the code as suggested by you,but it doesnt work.....
Logged

Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm afraid your only option is to run the sketch with the Serial monitor open, capture the data, and replicate the session by connecting to your smtp server using a network terminal (port 25). The code never checks the server's response, so there's no way to see which error messages, if any, are sent back by the server.
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 185
www.rocketscream.com
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm afraid your only option is to run the sketch with the Serial monitor open, capture the data, and replicate the session by connecting to your smtp server using a network terminal (port 25).
This is the best way to learn whether your syntax is wrong or right.

Quote
The code never checks the server's response, so there's no way to see which error messages, if any, are sent back by the server.
The Serial.find() function call can be used to check whether expected positive result is received from the server.

But, like spatula mentioned earlier, try replicating the session, so you know what to expect from the server.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I captures the messages from the server, at the point encode(); in the code when writing the data to mail, it gives error message when it reaches 1030 bytes and this email is not sent.
Logged

Rome, Italy
Offline Offline
Sr. Member
****
Karma: 20
Posts: 442
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That was more or less expected. It would be interesting to know more about the error, for example if it occurred while encoding the data in base64 or while sending the data to the server.

The second part of the test is to replicate the session by connecting to the mail server, using putty on port 25, and see if it accepts more than 1030 bytes of data.

At the moment we cannot exclude anything: a programming error, an error in the shield itself, or some restriction imposed by your provider (for example, though you can send large attachments, there can be a limit on the size of an individual part in a multipart message). Please consider that even if I wanted to run the test for you the code you posted wouldn't even compile.
Logged

Pages: [1]   Go Up
Jump to: