Please tell me how to reply by SMS for a received SMS


+ Reply to Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    May 2009
    Posts
    13

    Unhappy Please tell me how to reply by SMS for a received SMS

    My problem is this. I need to send SMS with data from a weighing scale to a given number when a SMS is received by the GSM modem. SMS sending part and data reading from the weighing scale part is ok but responding to SMS is not working in my program.
    Can anyone tell me how to send SMS to a given number when SMS is received to the GSM modem. My program is as follows.

    include "modedefs.bas"

    define OSC 4
    DEFINE HSER_SPBRG 25
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_BAUD 9600
    DEFINE HSER_CLROERR 1

    comRs232Out var PORTD.0
    comRs232in var PORTD.1
    weightGet var word
    smsGet var word

    Initialize:

    Start:
    HIGH smsRead
    HSEROUT ["AT+CMGF=1",13]
    PAUSE 500
    HSEROUT ["AT+CMGR=1",13]
    PAUSE 500
    HSERIN [smsGet]
    PAUSE 500

    IF smsGet = " " THEN
    goto Start
    ELSE
    SERIN comRs232In, T2400, [weightGet]
    PAUSE 500
    HSEROUT ["AT+CMGS=",34,"0718116393",34,13]
    PAUSE 500
    HSEROUT [weightGet,26]
    PAUSE 500
    HSEROUT ["AT+CMGL=1,4",26]
    PAUSE 15000
    goto Start
    ENDIF

  2. #2
    Join Date
    May 2008
    Location
    Italy
    Posts
    825

    Default

    but responding to SMS is not working in my program.
    This is quite simple providing that your modem is capable to hand text format (if you have only PDU format then you need to convert text to PDU first)

    Code:
    AT+CMGS=+39xxxxxxxxxxxx,13
    where +39 = international prefix for Italy (you will change as needed)
    xxxxxxxxxxxx = phone number you will send the sms.

    Immediatly after having sent this AT command you go listening the modem :

    answer should be: ">"

    When you receive this character then you sent your text (max 160 chars) terminating with 26

    HSEROUT ["This is my test",26] and you have sent your message.

    If you don't receive ">" within 5 seconds you must abort the command sending: HSEROUT [27] and repeat the command.

    Hope it will help you.

    Al.
    All progress began with an idea

  3. #3
    Join Date
    May 2009
    Posts
    13

    Thumbs up thanks

    Thank You im now testing it

    Quote Originally Posted by aratti View Post
    This is quite simple providing that your modem is capable to hand text format (if you have only PDU format then you need to convert text to PDU first)

    Code:
    AT+CMGS=+39xxxxxxxxxxxx,13
    where +39 = international prefix for Italy (you will change as needed)
    xxxxxxxxxxxx = phone number you will send the sms.

    Immediatly after having sent this AT command you go listening the modem :

    answer should be: ">"

    When you receive this character then you sent your text (max 160 chars) terminating with 26

    HSEROUT ["This is my test",26] and you have sent your message.

    If you don't receive ">" within 5 seconds you must abort the command sending: HSEROUT [27] and repeat the command.

    Hope it will help you.

    Al.

  4. #4
    Join Date
    May 2009
    Posts
    13

    Unhappy I just need to repply to a SMS

    I just need to know how to repply when a message received by the GSM Modam. It is great if i can repply only to a message from a specific number

  5. #5
    Join Date
    May 2008
    Location
    Italy
    Posts
    825

    Default

    If you want to answer to a received sms, then decode the message and grab the number of the sender, use it to reply with the same method as per previuos post.

    Al.
    All progress began with an idea

  6. #6
    Join Date
    May 2009
    Posts
    13

    Exclamation Thank You Very much, But I have more probd

    I have another problem in reading sms to a variable. Can u please let me know the code sequence to read sms in to a variable. (I am just a beginner to PIC programming). I know how to send AT command to read SMS but my problem is in getting Modem responces in to a variable.

  7. #7
    Join Date
    May 2008
    Location
    Italy
    Posts
    825

    Default

    I know how to send AT command to read SMS but my problem is in getting Modem responces in to a variable.
    First of all you have to connect your phone to your PC using HYPER TERMINAL and with the proper AT command obtain the complete string of one sms.

    Once the sms is on the screen you have to identify a starter (a number of characters at the begining of the string that never changes) very likely your phone will begin the string with the word "UNREAD", if this is case you can use this as a starter. You have also to identify the portions of the string that you need, count the character position (commencing from the last character of the starter) and the number of characters you will need. (For instance you will need the phone number of the sender and some part of the message. So count how many characters you have to skip from the end of the starter and the begining of the phone number, and from the end of the phone number to the begining of your text. Remember that space is one character)

    Once you have these informations, you will know the dimension of your byte arrays to contain the portion of string that you have selected and two numbers "n1" and "n2" which are the characters to skip to reach the portion of string that interest you.

    Code:
    ArrayNum     Var  BYTE [15]  ' here I assume the the phone number of the sender is 15 characters long. if shorter or longer adjust the array 
    
    ArrayTxt      Var  BYTE [50] ' here I assume that the sms text that interest you is 50 characters long. If your requirement is longer or shorter adjust the array

    Now, to fill your array, you send the AT command for reading your sms, and immediatly afterwards


    Code:
    HSEROUT ["AT^SMGR=1",13]  
    HSERIN 2000, NoSms,[WAIT("UNREAD"), Skip n1, Str ArrayNum\15, Skip n2,str ArrayTxt\50]
    If no sms are present, hserin will timeout to the label NoSms after 2 seconds, so include this label in your code.

    If the program doesn't jump to label NoSms then ArryNum will contain the phone number of the sender and ArrayTxt will contain the message.

    You can check ArrayNum and see if the answer can be sent or not. A simpler way to avoid to answer to the wrong message is to include a password within the text you send and check only the text. (In this case you don't need ArrayNum)

    If you need more help, you better tell me what you want to do.

    Al.
    Last edited by aratti; - 8th August 2009 at 10:59.
    All progress began with an idea

  8. #8
    Join Date
    May 2009
    Posts
    13

    Smile Thanks aratti

    Thanks aratti. You so kind. Ill check your codes.

  9. #9
    Join Date
    May 2009
    Posts
    13

    Question Another problem in reading data in to a array

    I used,

    Weight Get var BYTE[20]

    and use code to capture string comming via device serial port (The data I should send via SMS).

    SERIN comRs232In, T2400, 5000, Start, [weightGet]

    but it reads only first character of the string. I got stuck here.

  10. #10
    Join Date
    May 2008
    Location
    Italy
    Posts
    825

    Default

    Code:
    Weight Get var BYTE[20]
    
    SERIN comRs232In, T2400, 5000, Start, [weightGet]
    This is not the code I have suggested!

    Try:

    Code:
    Weight_Get var BYTE[20]
    Serin2 comRs232In, T2400, 5000, Start,[STR Weight_Get\20]
    Al.
    Last edited by aratti; - 17th August 2009 at 10:32.
    All progress began with an idea

  11. #11
    Join Date
    May 2009
    Posts
    13

    Exclamation I did it, Thanks - But more to know

    Yes I got it using following code

    SERIN2 comRs232In, 396, 1000, Start, [STR wGet\20]

    Thanks you arrati

    But I couldnot read message sender number and body of text correctly using

    HSERIN 5000, Start,[SKIP 8,WAIT("REC UNREAD"), Skip 3, Str ArrayNum\12, Skip 25, str ArrayTxt\6]

    even could not read any text of message even using

    HSERIN 5000, Start,[Str ArrayNum\12]

    Please help me

  12. #12
    Join Date
    May 2008
    Location
    Italy
    Posts
    825

    Default

    But I couldnot read message sender number and body of text correctly using
    Code:
    HSERIN 5000, Start,[SKIP 8,WAIT("REC UNREAD"), Skip 3, Str ArrayNum\12, Skip 25, str ArrayTxt\6]
    The SKIP instruction at the begining is wrong! remove it!

    Hserin will read the characters coming via RS232 and when the string indicated in The WAIT instruction is met than it start passing characters to your string.

    Make sure that your phone output the string "REC UNREAD" (remember that Wait is case sensitive) so if your phone output "rec unread" WAIT instruction will not identify the string and you will receive nothing.

    Code:
    HSERIN 5000, Start,[WAIT("REC UNREAD"), Skip 3, Str ArrayNum\12, Skip 25, str ArrayTxt\6]
    The above HSERIN code is the correct one, providing your phone send the "REC UNREAD" in uppercase and the skip values (3 and 25) are corrected, but this is something that you must verify.

    Al.
    All progress began with an idea

Similar Threads

  1. Problem with SMS IO Controller
    By dario.costa in forum GSM
    Replies: 4
    Last Post: - 30th November 2009, 07:04
  2. Replies: 288
    Last Post: - 25th August 2008, 16:53
  3. Reading a SMS to an array
    By KA5MAL in forum GSM
    Replies: 3
    Last Post: - 17th June 2008, 17:24
  4. Rs485 Using Hserin/hserout
    By koossa in forum mel PIC BASIC Pro
    Replies: 27
    Last Post: - 31st January 2008, 09:42

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts