Shop OBEX P1 Docs P2 Docs Learn Events
Reading SMS — Parallax Forums

Reading SMS

PVJohnPVJohn Posts: 60
edited 2006-02-06 15:44 in BASIC Stamp
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 [noparse][[/noparse]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, [noparse][[/noparse]"AT+CMGS=",34,"+15128318653",34,CR]
· SERIN RXfromModem, Baud, [noparse][[/noparse]WAIT (">")]
·
· SEROUT TXtoModem, Baud, [noparse][[/noparse]"My message.",CR]
· SEROUT TXtoModem, Baud, [noparse][[/noparse]ControlZ,CR]
· DEBUG "sent ctrl-z",CR,LF
· SERIN RXfromModem, Baud, [noparse][[/noparse]WAIT ("OK")]
· DEBUG "Got OK from modem",CR,LF
· DEBUG "Message has been send",CR,LF
RETURN

Thanks for your help.

PVJohn

Comments

  • mc9180mc9180 Posts: 3
    edited 2006-02-01 04:48
    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, [noparse][[/noparse]"ATDT 6133331234"]
    SEROUT 1, GPS4800, [noparse][[/noparse]CR]

    Thanks
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-01 08:22
    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 BakerPaul Baker Posts: 6,351
    edited 2006-02-01 15:37
    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 BakerPaul Baker Posts: 6,351
    edited 2006-02-01 16:48
    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
  • mc9180mc9180 Posts: 3
    edited 2006-02-01 16:59
    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 BatesBruce Bates Posts: 3,045
    edited 2006-02-01 18:33
    mc9180 -

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

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

    and see how that goes.

    Regards,

    Bruce Bates
  • ktekxktekx Posts: 71
    edited 2006-02-02 10:13
    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?
  • mc9180mc9180 Posts: 3
    edited 2006-02-03 22:02
    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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-06 15:44
    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
Sign In or Register to comment.