By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,399 Members | 886 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,399 IT Pros & Developers. It's quick & easy.

Telit GM682-GPS #SEMAIL returns ERRO

P: 6
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.se) with the same result.

Expand|Select|Wrap|Line Numbers
  1. #Use serial
  2. import SER
  3. #Use build in module
  4. import MOD
  5. #Use AT command interface
  6. import MDM
  7. #Use GPS
  8. import GPS
  9. #Use sys?
  10. import sys
  11.  
  12. # ########################################################### #
  13. # this values must be configured with valid ones..
  14. # the one here are only for demo.
  15. #
  16. EMAIL_ADDRESS = "xxx@xxx.xx"  # Yes, there's normally something else here... :)
  17. # this is the email address of the destinee of the mail (To:)
  18. #
  19. MY_EMAIL_ADDR = "xxx@xxx.xx"  # Yes, there's normally something else here... :)
  20. # this is the email address of the source of the mail (From:)
  21. # usually (unless SMTP server permits relay) this must match
  22. # with MAIL_USER and MAIL_PASSW.
  23. #
  24. APN           = "online.telia.se"
  25. # this is the access point for GPRS - ask your network operator
  26. #
  27. GPRS_USERID   = "guest"
  28. # this is the User ID for GPRS - ask your network operator
  29. #
  30. GPRS_PASSW    = "guest"
  31. # this is the Password for GPRS - ask your network operator
  32. #
  33. SMTP_SERVER   = "mail.messagingengine.com"
  34. # this is the SMTP server that forwards the mail
  35. #
  36. MAIL_USER     = "xxx@xxx.xx"  # Yes, there's normally something else here... :)
  37. # this is the Username for the SMTP server
  38. #
  39. MAIL_PASSW    = "*********"  # Yes, there's normally something else here... :) 
  40. # this is the Password for the SMTP server
  41. #
  42. # ########################################################### #
  43.  
  44. def sendemail():
  45.   global sendingemail
  46.   res = MDM.send('AT#SEMAIL="', 0)
  47.   res = MDM.send(EMAIL_ADDRESS, 0)
  48.   res = MDM.send('",', 0)
  49.   res = MDM.send('"test email"', 0)
  50.   res = MDM.send(',0', 0)
  51.   res = MDM.sendbyte(0x0d, 0)
  52.   res = MDM.receive(100)
  53.   print 'AT#SEMAIL="%s","test email",0 returned %s' % (EMAIL_ADDRESS, res)
  54.   res = MDM.send('email sent from python script', 0)
  55.   print 'email content returned %s' % res
  56.   res = MDM.send('\x1a', 0)
  57.   print 'x1a returned %s' % res
  58.   sendingemail = 1
  59.   print 'sending email ...'
  60.  
  61.  
  62. SER.set_speed('115200','8N1')
  63. class SerWriter:
  64.     def write(self,s):
  65.         SER.send(s+'\r')
  66. sys.stdout = sys.stderr = SerWriter()
  67.  
  68.  
  69. print 'Running...'
  70.  
  71. MDMdata = ''
  72. sendingemail = 0
  73.  
  74. print 'initialize'
  75. res = MDM.send('AT+CGDCONT=1,"IP","',0)
  76. res = MDM.send(APN,0)
  77. res = MDM.send('","0.0.0.0",0,0\r', 0)
  78. res = MDM.receive(10)
  79. print 'AT+CGDCONT=1,"IP","%s","0.0.0.0",0,0 returned %s' % (APN, res)
  80. res = MDM.send('AT#USERID="',0)
  81. res = MDM.send(GPRS_USERID,0)
  82. res = MDM.send('"\r', 0)
  83. res = MDM.receive(10)
  84. print 'AT#USERID="%s" returned %s' % (GPRS_USERID, res)
  85. res = MDM.send('AT#PASSW="',0)
  86. res = MDM.send(GPRS_PASSW,0)
  87. res = MDM.send('"\r', 0)
  88. res = MDM.receive(10)
  89. print 'AT#PASSW="%s" returned %s' % (GPRS_PASSW, res)
  90. res = MDM.send('AT#ESMTP="',0)
  91. res = MDM.send(SMTP_SERVER,0)
  92. res = MDM.send('"\r', 0)
  93. res = MDM.receive(10)
  94. print 'AT#ESMTP="%s" returned %s' % (SMTP_SERVER, res)
  95. res = MDM.send('AT#GPRS=0\r', 0)
  96. res = MDM.receive(10)
  97. print 'AT#GPRS=0 returned %s' % res
  98. res = MDM.send('AT#EUSER="',0)
  99. res = MDM.send(MAIL_USER,0)
  100. res = MDM.send('"\r', 0)
  101. res = MDM.receive(10)
  102. print 'AT#EUSER="%s" returned %s' % (MAIL_USER, res)
  103. res = MDM.send('AT#EPASSW="',0)
  104. res = MDM.send(MAIL_PASSW,0)
  105. res = MDM.send('"\r', 0)
  106. res = MDM.receive(10)
  107. print 'AT#EPASSW="%s" returned %s' % (MAIL_PASSW, res)
  108. res = MDM.send('AT#EADDR="',0)
  109. res = MDM.send(MY_EMAIL_ADDR,0)
  110. res = MDM.send('"\r', 0)
  111. res = MDM.receive(10)
  112. print 'AT#EADDR="%s" returned %s' % (MY_EMAIL_ADDR, res)
  113. res = MDM.send('AT#ESAV\r', 0)
  114. res = MDM.receive(20)
  115. print 'AT#ESAV returned %s' % res
  116.  
  117. timerA = MOD.secCounter()
  118. timerAstop = timerA + 10
  119. timerArunning = 1
  120.  
  121. while 1:
  122.  
  123.   if timerArunning:
  124.     timerA = MOD.secCounter()
  125.     if timerA > timerAstop:
  126.       res = MDM.send('AT#EMAILACT=1\r', 0)
  127.       res = MDM.receive(100)
  128.       print 'AT#EMAILACT=1 returned %s' % res
  129.       if(res.find('OK') != -1):
  130.         res = MDM.send('AT+CGDCONT?\r', 0)
  131.         res = MDM.receive(20)
  132.         print 'AT+CGDCONT? returned %s' % res
  133.         res = MDM.send('AT+COPS?\r', 0)
  134.         res = MDM.receive(20)
  135.         print 'AT+COPS? returned %s' % res
  136.         res = MDM.send('AT+CSQ\r', 0)
  137.         res = MDM.receive(20)
  138.         print 'AT+CSQ returned %s' % res
  139.         res = MDM.send('AT+CGATT?\r', 0)
  140.         res = MDM.receive(20)
  141.         print 'AT+CGATT? returned %s' % res
  142.  
  143.         print 'send email'
  144.         sendemail()
  145.         timerArunning = 0
  146.         MOD.sleep(200)
  147.       else:
  148.         print 'email init failed'
  149.         MOD.sleep(200)
  150.  
  151.   MDMdata = MDM.read()
  152.  
  153.   if MDMdata != '':
  154.     if sendingemail:
  155.       print 'MDM read data %s' % MDMdata
  156.       sendingemail = 0
  157.     else:
  158.       print 'unexpected data'
  159.       print 'MDM read data %s' % MDMdata
May 31 '09 #1
Share this Question
Share on Google+
9 Replies


YarrOfDoom
Expert 100+
P: 1,247
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?
May 31 '09 #2

P: 6
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.
May 31 '09 #3

YarrOfDoom
Expert 100+
P: 1,247
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:
Expand|Select|Wrap|Line Numbers
  1. def sendemail():
  2. global sendingemail
  3. res = MDM.send('AT#SEMAIL="', 0)
  4. res = MDM.send(EMAIL_ADDRESS, 0)
  5. res = MDM.send('",', 0)
  6. res = MDM.send('"test email"', 0)
  7. res = MDM.send(',0', 0)
  8. res = MDM.sendbyte(0x0d, 0)
  9. res = MDM.receive(100)
  10. print 'AT#SEMAIL="%s","test email",0 returned %s' % (EMAIL_ADDRESS, res)
  11. res = MDM.send('email sent from python script', 0)
  12. print 'email content returned %s' % res
  13. res = MDM.send('\x1a', 0)
  14. print 'x1a returned %s' % res
  15. sendingemail = 1
  16. print 'sending email ...'
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_Commands_Reference_Guide_r5" and "Telit_Easy_Script_in_Python_r9" 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).
May 31 '09 #4

P: 6
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.
May 31 '09 #5

YarrOfDoom
Expert 100+
P: 1,247
I've found 2 notes in the AT Commands Reference that are important here:
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.
May 31 '09 #6

P: 6
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...

Expand|Select|Wrap|Line Numbers
  1. #Use serial
  2. import SER
  3. #Use build in module
  4. import MOD
  5. #Use AT command interface
  6. import MDM
  7. #Use GPS
  8. import GPS
  9. #Use sys?
  10. import sys
  11.  
  12. def sendemail():
  13.   global sendingemail
  14.   res = MDM.send('AT#SCFG=1,1,300,90,600,50\r', 0)
  15.   res = MDM.receive(100)
  16.   print 'AT#SCFG=1,1,300,90,600,50 returned %s' % res
  17.   res = MDM.send('AT#SGACT=1,1,"",""\r', 0)
  18.   res = MDM.receive(100)
  19.   print 'AT#SGACT=1,1,"","" returned %s' % res
  20.   if(res.find('OK') != -1):
  21.     res = MDM.send('AT#EMAILD="tmp@imap.cc","Email test",0\r', 0)
  22.     res = ""
  23.     loopCheck = 1
  24.     while (loopCheck == 1):
  25.       res1 = MDM.receive(100)
  26.       res = res + res1
  27.       print 'res: %s' % res
  28.       if (res.find('>') != -1):
  29.         print 'AT#EMAILD="tmp@imap.cc","Email test",0 returned %s' % res
  30.         res = MDM.send('email sent from python script', 5)
  31.         res = MDM.sendbyte(0x1a, 5)
  32.         print 'email content returned %s' % res
  33.         loopCheck = 0
  34.   sendingemail = 1
  35.   print 'sending email ...'
  36.  
  37. SER.set_speed('115200','8N1')
  38. class SerWriter:
  39.     def write(self,s):
  40.         SER.send(s+'\r')
  41. sys.stdout = sys.stderr = SerWriter()
  42.  
  43.  
  44. print 'Running...'
  45.  
  46. MDMdata = ''
  47. sendingemail = 0
  48.  
  49. print 'initialize...'
  50.  
  51. res = MDM.send('AT+CGDCONT=1,"IP","online.telia.se","0.0.0.0",0,0\r', 0)
  52. res = MDM.receive(20)
  53. print 'AT+CGDCONT=1,"IP","online.telia.se","0.0.0.0",0,0 returned %s' % res
  54.  
  55. res = MDM.send('AT#ESMTP="mail.messagingengine.com"\r',0)
  56. res = MDM.receive(20)
  57. print 'AT#ESMTP="mail.messagingengine.com" returned %s' % res
  58.  
  59. res = MDM.send('AT#EUSER="xxx@xxx.xx"\r',0)
  60. res = MDM.receive(20)
  61. print 'AT#EUSER="xxx@xxx.xx" returned %s' % res
  62.  
  63. res = MDM.send('AT#EPASSW="**********"\r',0)
  64. res = MDM.receive(20)
  65. print 'AT#EPASSW="**********" returned %s' % res
  66.  
  67. res = MDM.send('AT#EADDR="dre@fastmail.net"\r',0)
  68. res = MDM.receive(20)
  69. print 'AT#EADDR="dre@fastmail.net" returned %s' % res
  70.  
  71. res = MDM.send('AT#ESAV\r', 0)
  72. res = MDM.receive(20)
  73. print 'AT#ESAV returned %s' % res
  74.  
  75. timerA = MOD.secCounter()
  76. timerAstop = timerA + 10
  77. timerArunning = 1
  78.  
  79. while 1:
  80.  
  81.   if timerArunning:
  82.     timerA = MOD.secCounter()
  83.     if timerA > timerAstop:
  84.       print 'AT#EMAILACT=1 returned %s' % res
  85.       if(res.find('OK') != -1):
  86.         print 'send email'
  87.         sendemail()
  88.         timerArunning = 0
  89.         MOD.sleep(200)
  90.       else:
  91.         print 'email init failed'
  92.         MOD.sleep(200)
  93.  
  94.   MDMdata = MDM.read()
  95.  
  96.   if MDMdata != '':
  97.     if sendingemail:
  98.       print 'MDM read data %s' % MDMdata
  99.       sendingemail = 0
  100.     else:
  101.       print 'unexpected data'
  102.       print 'MDM read data %s' % MDMdata
  103.  
May 31 '09 #7

YarrOfDoom
Expert 100+
P: 1,247
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.
May 31 '09 #8

P: 6
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#EMAILD="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.
Jun 1 '09 #9

P: 6
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!
Jun 1 '09 #10

Post your reply

Sign in to post your reply or Sign up for a free account.