PDA

View Full Version : Reading SMS



PVJohn
01-14-2006, 12:08 PM
Hello,·I would like·to read SMS from my cell phone and print it in debug window, but I couldn't find any good example. I don't know what's in the message and how long it is, so·I can't use [WAIT ("anything")] to·search for the string and I must be able to read 160 characters. I'm using BS2px at 2400. This is my code to send·SMS out.

'{$STAMP BS2px}
'{$PBASIC 2.5}
'
' ------------------------------------------------------------------------------
' I/O Definitions
' ------------------------------------------------------------------------------
· RXfromModem·· CON···· 0··· ' receive (from modem)
· TXtoModem······ CON···· 1··· ' transmit (to modem)
' ------------------------------------------------------------------------------
' Constants
' ------------------------------------------------------------------------------
· Baud···· CON···· 1646····· ' 2400-N-8-1
· ControlZ CON···· 26······· ' Escape character·
' ------------------------------------------------------------------------------
' Program Code
' ------------------------------------------------------------------------------
Main:
· GOSUB SendText
· STOP
' ------------------------------------------------------------------------------
' Subroutines
' ------------------------------------------------------------------------------
SendText:
· DEBUG "Setting receiving number",CR,LF
· SEROUT TXtoModem, Baud, ["AT+CMGS=",34,"+15128318653",34,CR]
· SERIN RXfromModem, Baud, [WAIT (">")]
·
· SEROUT TXtoModem, Baud, ["My message.",CR]
· SEROUT TXtoModem, Baud, [ControlZ,CR]
· DEBUG "sent ctrl-z",CR,LF
· SERIN RXfromModem, Baud, [WAIT ("OK")]
· DEBUG "Got OK from modem",CR,LF
· DEBUG "Message has been send",CR,LF
RETURN

Thanks for your help.

PVJohn

mc9180
02-01-2006, 11:48 AM
Hey PVJohn,

I am trying to do a similar project where I want to program a BS2 to send SMS messages using a cell phone. Do you have any success sending commands to a cell phone using the BS2? I can't even send simple commands such as dialing out to the cell phone. Here's my code:

GPS4800 CON 500 '4800N-8-1

SEROUT 1, GPS4800, ["ATDT 6133331234"]
SEROUT 1, GPS4800, [CR]

Thanks

Bruce Bates
02-01-2006, 03:22 PM
mc9180 -

You need to change your baudmode for the BS-2 to one of the following for 4800 BPS:

4800 8-N-1 TRUE = 188

4800 8-N-1 Inverted = 16572

Regards,

Bruce Bates

Paul Baker
02-01-2006, 10:37 PM
This is one of those situations where google is your friend, typing "SMS format" into yahoo, the second hit ( http://home.student.utwente.nl/s.p.ekkebus/portfolio/resource/sms_pdu.html#SMS·) shows that the message length is encoded in the data structure. So you'd fetch the "Length of User data" and loop to recieve all the characters.

It even has a HEX-> message and message->HEX conversion utiliities so you can easily perform sanity checks on your PBASIC code to make sure it is in agreement (working properly).

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10

Paul Baker
02-01-2006, 11:48 PM
An aditional note, the SMS data structure is a variable length format beyond just the tail message, the length of the SMSC info and length of the sender address are both variable length and these fields are both incorporated before the length of the User data is provided. This means the length of the user data field is not in a fixed location in the data structure, hence you must parse the data as it comes in,·in order to retrieve the length of the User data field.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10

mc9180
02-01-2006, 11:59 PM
Bruce Bates,

Sorry, I forgot to mention that I have a BS2sx chip.

Therefore I tried both:
4800 8-N-1 TRUE = 500
4800 8-N-1 Inverted = 16884

What happens it that after the BS2sx chip sends the ATDT command to the cell phone, I DO get a audio response from the phone but it doesn't dial out as it's supposed to. (I've tried 9600, 2400 bit rates also)

For example, if I connect the cell phone (Sony Ericsson T610) to my PC with a serial data cable and I send the ATDT command using hyperterminal, the cell phone would beep once and the cell display will say it is dialing out.

If the BS2sx sends out the ATDT command, the phone just beeps once and does not dial out like in the case above.

Bruce Bates
02-02-2006, 01:33 AM
mc9180 -

That being the case, I'd change the SEROUT command to look like this:

SEROUT 1, GPS4800, ["ATDT6133331234", CR]

and see how that goes.

Regards,

Bruce Bates

ktekx
02-02-2006, 05:13 PM
mc9180, I have been trying to interface a sony ericsson gsm cell phone to my stamp for just that purpose as well. Instead of making it dial, I've been trying to make it respond with an "OK" when I send it an "AT". I don't know if my baud settings are off, but I am getting garbage responses, which is more luck than I've had lately.

How did you interface your cell phone to your basic stamp? Directly by the pins of the cell or through a data cable?

mc9180
02-04-2006, 05:02 AM
ktekx,

I have the same problem as you. When I use the serial cable to connect the SE phone to my PC, I can communicate fine between the two using hyperterminal. But when connecting the BS2, I get garbage responses.

I interfaced the BS2 and the phone by connecting the pins of the data cable to the I/O pins of the BS2.

I connected the BS2 SEROUT I/O -> Pin3 of the male DB9 connector
" " SERIN I/O -> Pin 2 " "
" " VSS -> Pin5 " " (ground)

Chris Savage
02-06-2006, 10:44 PM
The pins of the phone are most likely RS-232, whereas the BASIC Stamp pins are TTL.· Also the RS-232 would be inverted mode while the Stamp pins would be true mode.· You will need a MAX232 or similar driver.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)