Telit GM682-GPS #SEMAIL returns ERRO

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krachor
    New Member
    • May 2009
    • 6

    Telit GM682-GPS #SEMAIL returns ERRO

    There appears to be some very knowledgeable people hanging around this forum so I post this question here even if it only indirectly is python related.

    #SEMAIL returns ERROR

    Is there any way of narrowing down what's wrong?

    I've basically used the email sending example in pythonwin.
    The APN and SMTP information is correct. I've verified that with my cellphone. I'm a little bit unsure about the AT#USERID and AT#PASSW. I've tried both nothing and guest/guest (online.telia.s e) with the same result.

    Code:
    #Use serial
    import SER
    #Use build in module
    import MOD
    #Use AT command interface
    import MDM
    #Use GPS
    import GPS
    #Use sys?
    import sys
    
    # ########################################################### #
    # this values must be configured with valid ones..
    # the one here are only for demo.
    #
    EMAIL_ADDRESS = "xxx@xxx.xx"  # Yes, there's normally something else here... :)
    # this is the email address of the destinee of the mail (To:)
    #
    MY_EMAIL_ADDR = "xxx@xxx.xx"  # Yes, there's normally something else here... :)
    # this is the email address of the source of the mail (From:)
    # usually (unless SMTP server permits relay) this must match
    # with MAIL_USER and MAIL_PASSW.
    #
    APN           = "online.telia.se"
    # this is the access point for GPRS - ask your network operator
    #
    GPRS_USERID   = "guest"
    # this is the User ID for GPRS - ask your network operator
    #
    GPRS_PASSW    = "guest"
    # this is the Password for GPRS - ask your network operator
    #
    SMTP_SERVER   = "mail.messagingengine.com"
    # this is the SMTP server that forwards the mail
    #
    MAIL_USER     = "xxx@xxx.xx"  # Yes, there's normally something else here... :)
    # this is the Username for the SMTP server
    #
    MAIL_PASSW    = "*********"  # Yes, there's normally something else here... :) 
    # this is the Password for the SMTP server
    #
    # ########################################################### #
    
    def sendemail():
      global sendingemail
      res = MDM.send('AT#SEMAIL="', 0)
      res = MDM.send(EMAIL_ADDRESS, 0)
      res = MDM.send('",', 0)
      res = MDM.send('"test email"', 0)
      res = MDM.send(',0', 0)
      res = MDM.sendbyte(0x0d, 0)
      res = MDM.receive(100)
      print 'AT#SEMAIL="%s","test email",0 returned %s' % (EMAIL_ADDRESS, res)
      res = MDM.send('email sent from python script', 0)
      print 'email content returned %s' % res
      res = MDM.send('\x1a', 0)
      print 'x1a returned %s' % res
      sendingemail = 1
      print 'sending email ...'
    
    
    SER.set_speed('115200','8N1')
    class SerWriter:
        def write(self,s):
            SER.send(s+'\r')
    sys.stdout = sys.stderr = SerWriter()
    
        
    print 'Running...'
    
    MDMdata = ''
    sendingemail = 0
    
    print 'initialize'
    res = MDM.send('AT+CGDCONT=1,"IP","',0)
    res = MDM.send(APN,0)
    res = MDM.send('","0.0.0.0",0,0\r', 0)
    res = MDM.receive(10)
    print 'AT+CGDCONT=1,"IP","%s","0.0.0.0",0,0 returned %s' % (APN, res)
    res = MDM.send('AT#USERID="',0)
    res = MDM.send(GPRS_USERID,0)
    res = MDM.send('"\r', 0)
    res = MDM.receive(10)
    print 'AT#USERID="%s" returned %s' % (GPRS_USERID, res)
    res = MDM.send('AT#PASSW="',0)
    res = MDM.send(GPRS_PASSW,0)
    res = MDM.send('"\r', 0)
    res = MDM.receive(10)
    print 'AT#PASSW="%s" returned %s' % (GPRS_PASSW, res)
    res = MDM.send('AT#ESMTP="',0)
    res = MDM.send(SMTP_SERVER,0)
    res = MDM.send('"\r', 0)
    res = MDM.receive(10)
    print 'AT#ESMTP="%s" returned %s' % (SMTP_SERVER, res)
    res = MDM.send('AT#GPRS=0\r', 0)
    res = MDM.receive(10)
    print 'AT#GPRS=0 returned %s' % res
    res = MDM.send('AT#EUSER="',0)
    res = MDM.send(MAIL_USER,0)
    res = MDM.send('"\r', 0)
    res = MDM.receive(10)
    print 'AT#EUSER="%s" returned %s' % (MAIL_USER, res)
    res = MDM.send('AT#EPASSW="',0)
    res = MDM.send(MAIL_PASSW,0)
    res = MDM.send('"\r', 0)
    res = MDM.receive(10)
    print 'AT#EPASSW="%s" returned %s' % (MAIL_PASSW, res)
    res = MDM.send('AT#EADDR="',0)
    res = MDM.send(MY_EMAIL_ADDR,0)
    res = MDM.send('"\r', 0)
    res = MDM.receive(10)
    print 'AT#EADDR="%s" returned %s' % (MY_EMAIL_ADDR, res)
    res = MDM.send('AT#ESAV\r', 0)
    res = MDM.receive(20)
    print 'AT#ESAV returned %s' % res
          
    timerA = MOD.secCounter()
    timerAstop = timerA + 10
    timerArunning = 1
    
    while 1:
    
      if timerArunning:
        timerA = MOD.secCounter()
        if timerA > timerAstop:
          res = MDM.send('AT#EMAILACT=1\r', 0)
          res = MDM.receive(100)
          print 'AT#EMAILACT=1 returned %s' % res
          if(res.find('OK') != -1):
            res = MDM.send('AT+CGDCONT?\r', 0)
            res = MDM.receive(20)
            print 'AT+CGDCONT? returned %s' % res
            res = MDM.send('AT+COPS?\r', 0)
            res = MDM.receive(20)
            print 'AT+COPS? returned %s' % res
            res = MDM.send('AT+CSQ\r', 0)
            res = MDM.receive(20)
            print 'AT+CSQ returned %s' % res
            res = MDM.send('AT+CGATT?\r', 0)
            res = MDM.receive(20)
            print 'AT+CGATT? returned %s' % res
    
            print 'send email'
            sendemail()
            timerArunning = 0
            MOD.sleep(200)
          else:
            print 'email init failed'
            MOD.sleep(200)
    
      MDMdata = MDM.read()
    
      if MDMdata != '':
        if sendingemail:
          print 'MDM read data %s' % MDMdata
          sendingemail = 0
        else:
          print 'unexpected data'
          print 'MDM read data %s' % MDMdata
    Last edited by bvdet; May 31 '09, 03:35 PM. Reason: Add code tags
  • YarrOfDoom
    Recognized Expert Top Contributor
    • Aug 2007
    • 1243

    #2
    Hi krachor, welcome to Bytes.
    Please use code-tags (put [code] in front of your code and [/code] where it ends), as this improves the readability of your code.
    Please read the posting guidelines for more details on how to make a good post.

    Now, about your code: wouldn't it be handier to use smtplib, to simplify the code for sending the mail?
    And have you tried 'guest' as GPRS_USERID and nothing for GPRS_PASSW?

    Comment

    • krachor
      New Member
      • May 2009
      • 6

      #3
      Sorry about the missing code quotes. I didn’t find an option to edit my post though.

      Tried nothing for GPRS_PASSW and guest for GPRS_USERID but with the same result.

      Would smtplib actually work for a telit module? Wouldn’t have expected that to be implemented.

      Comment

      • YarrOfDoom
        Recognized Expert Top Contributor
        • Aug 2007
        • 1243

        #4
        I just found a Telit-Python manual for your phone, and smtplib indeed isn't included.

        I also believe your error is located in this part of your code:
        [code=Python]def sendemail():
        global sendingemail
        res = MDM.send('AT#SE MAIL="', 0)
        res = MDM.send(EMAIL_ ADDRESS, 0)
        res = MDM.send('",', 0)
        res = MDM.send('"test email"', 0)
        res = MDM.send(',0', 0)
        res = MDM.sendbyte(0x 0d, 0)
        res = MDM.receive(100 )
        print 'AT#SEMAIL="%s" ,"test email",0 returned %s' % (EMAIL_ADDRESS, res)
        res = MDM.send('email sent from python script', 0)
        print 'email content returned %s' % res
        res = MDM.send('\x1a' , 0)
        print 'x1a returned %s' % res
        sendingemail = 1
        print 'sending email ...'[/code]
        I quote it here to highlight it for other people.

        Could it be, that you should leave a longer timeout for your sent commands?
        Try changing the second argument of every MDM.send(command,timeout) into 5 (that's for a timeout of 0.5 seconds).

        Here's also a link for everyone working on this problem with manuals for about everything about the Telit GM862-GPS. Especially "Telit_AT_Comma nds_Reference_G uide_r5" and "Telit_Easy_Scr ipt_in_Python_r 9" are important.

        EDIT:You should indeed leave a longer timeout, because according to the AT Commands Reference, it can take up to 3 minutes to send a mail with SEMAIL (it's probably a lot shorter if there's no attachment, but you left absolutely no timeout).

        Comment

        • krachor
          New Member
          • May 2009
          • 6

          #5
          Changed the timeout to 5 but that didn't generate any changes.

          The print output is:

          AT#EMAILACT=1 returned
          OK

          AT+CGDCONT? returned
          +CGDCONT: 1,"IP","online. telia.se","0.0. 0.0",0,0

          OK

          AT+COPS? returned
          +COPS: 0,0,"TELIA S"

          OK

          AT+CGATT: 1

          OK

          send email
          AT#SEMAIL="tmp@ imap.cc","test email",0 returned
          >
          email content returned 1
          sending email ...
          MDM read data
          ERROR

          I've re-written the print output so there might be typos.
          The first initializations just returns OK.

          Comment

          • YarrOfDoom
            Recognized Expert Top Contributor
            • Aug 2007
            • 1243

            #6
            I've found 2 notes in the AT Commands Reference that are important here:
            Originally posted by AT Commands Reference about SEMAIL
            Note: Care must be taken to ensure that during the command execution,
            no other commands are issued.

            Note: This command is obsolete. It’s suggested to use the couple #EMAILACT
            and #EMAILD instead of it.

            Comment

            • krachor
              New Member
              • May 2009
              • 6

              #7
              That explains a little at least. I've been looking at an older version of the "Easy GPRS User Guide". It even states that there are three different procedures for sending email in the r4 version even though only two are listed now.

              AT#SGACT=1,1,"" ,"" returns #SGACT: 10.145.54.21 so GPRS connects correctly now.

              AT#EMAILD=.... returns ERROR though.

              This is the code I have right now.
              It's far from well written but right now I'm only interested in getting it to work. I'll tidy it up later...
              Yes, I've removed the account information so that's not the problem. :)
              I've both double and triple checked the acc. info...

              Code:
              #Use serial
              import SER
              #Use build in module
              import MOD
              #Use AT command interface
              import MDM
              #Use GPS
              import GPS
              #Use sys?
              import sys
              
              def sendemail():
                global sendingemail
                res = MDM.send('AT#SCFG=1,1,300,90,600,50\r', 0)
                res = MDM.receive(100)
                print 'AT#SCFG=1,1,300,90,600,50 returned %s' % res
                res = MDM.send('AT#SGACT=1,1,"",""\r', 0)
                res = MDM.receive(100)
                print 'AT#SGACT=1,1,"","" returned %s' % res
                if(res.find('OK') != -1):
                  res = MDM.send('AT#EMAILD="tmp@imap.cc","Email test",0\r', 0)
                  res = ""
                  loopCheck = 1
                  while (loopCheck == 1):
                    res1 = MDM.receive(100)
                    res = res + res1
                    print 'res: %s' % res
                    if (res.find('>') != -1):
                      print 'AT#EMAILD="tmp@imap.cc","Email test",0 returned %s' % res
                      res = MDM.send('email sent from python script', 5)
                      res = MDM.sendbyte(0x1a, 5)
                      print 'email content returned %s' % res
                      loopCheck = 0
                sendingemail = 1
                print 'sending email ...'
                
              SER.set_speed('115200','8N1')
              class SerWriter:
                  def write(self,s):
                      SER.send(s+'\r')
              sys.stdout = sys.stderr = SerWriter()
              
                  
              print 'Running...'
              
              MDMdata = ''
              sendingemail = 0
              
              print 'initialize...'
              
              res = MDM.send('AT+CGDCONT=1,"IP","online.telia.se","0.0.0.0",0,0\r', 0)
              res = MDM.receive(20)
              print 'AT+CGDCONT=1,"IP","online.telia.se","0.0.0.0",0,0 returned %s' % res
              
              res = MDM.send('AT#ESMTP="mail.messagingengine.com"\r',0)
              res = MDM.receive(20)
              print 'AT#ESMTP="mail.messagingengine.com" returned %s' % res
              
              res = MDM.send('AT#EUSER="xxx@xxx.xx"\r',0)
              res = MDM.receive(20)
              print 'AT#EUSER="xxx@xxx.xx" returned %s' % res
              
              res = MDM.send('AT#EPASSW="**********"\r',0)
              res = MDM.receive(20)
              print 'AT#EPASSW="**********" returned %s' % res
              
              res = MDM.send('AT#EADDR="dre@fastmail.net"\r',0)
              res = MDM.receive(20)
              print 'AT#EADDR="dre@fastmail.net" returned %s' % res
              
              res = MDM.send('AT#ESAV\r', 0)
              res = MDM.receive(20)
              print 'AT#ESAV returned %s' % res
                    
              timerA = MOD.secCounter()
              timerAstop = timerA + 10
              timerArunning = 1
              
              while 1:
              
                if timerArunning:
                  timerA = MOD.secCounter()
                  if timerA > timerAstop:
                    print 'AT#EMAILACT=1 returned %s' % res
                    if(res.find('OK') != -1):
                      print 'send email'
                      sendemail()
                      timerArunning = 0
                      MOD.sleep(200)
                    else:
                      print 'email init failed'
                      MOD.sleep(200)
              
                MDMdata = MDM.read()
              
                if MDMdata != '':
                  if sendingemail:
                    print 'MDM read data %s' % MDMdata
                    sendingemail = 0
                  else:
                    print 'unexpected data'
                    print 'MDM read data %s' % MDMdata

              Comment

              • YarrOfDoom
                Recognized Expert Top Contributor
                • Aug 2007
                • 1243

                #8
                Looks like you forgot about the timeouts again :)
                Remember that a timeout-value of 10 equals 1 second, and that on page 16 and following of the AT Commands Reference is a table with the maximum time it can take for certain commands to give response.
                And under that table is a paragraph about the recommended timeout values.

                Comment

                • krachor
                  New Member
                  • May 2009
                  • 6

                  #9
                  The MDM.send command buffer is 4096 bytes large so I doubt that’s the problem but you are right. There should definitely be a timeout value supplied that differs from 0.

                  I should also check the return value of all send commands to verify that it didn’t timeout no matter what timeout value I supply. I do however get the correct response from every command sent to the MDM module indicating that there wasn’t a timeout in the send functionality. <CR> is the last byte in most strings sent and without <CR> there won’t be a reply. I will also continuously monitor the reply string instead of using receive with a timeout. I should act as soon as I receive an ERROR or OK in return. But as I said earlier, I’ll tidy up the code after I get it working. :)

                  MDM.send('AT#EM AILD="tmp@imap. cc","Email test",0\r', 0) returns the ‘>’ char indicating that it has received and accepted the EMAILD command. It does however return ERROR after the content of the mail has been sent.
                  The SELINT is default 2 for the 862-GPS version so AT#SGACT sent earlier is enough to activate the GPRS.
                  I’ll try a different SMTP server even though the one I’m trying to use now is working with the same SIM card in a normal phone. I wonder if I missed to activate something but I don’t know what that could be.

                  Comment

                  • krachor
                    New Member
                    • May 2009
                    • 6

                    #10
                    My service provider is probably the problem. They are apparently blocking port 25. When I tried it in my phone it automatically enabled ssl that uses another port. I can't find any information that this module supports ssl so I'm probably screwed. Thanks for the help guys!

                    Comment

                    Working...