Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to can i Extract Sms Message From AT command response using 8051

Status
Not open for further replies.

Davechika

Newbie level 6
Joined
Oct 8, 2009
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Port-Harcourt,Nigeria
Activity points
1,357
Hi, i want to extract sms message from AT+CMGR=1; AT command issued by 8051 to gsm Modem,
i get a response like this
+CMGR:"REC READ", "+2347060580383" "Date and time", sms text here
Ok.
i want to extract the sms text here using c/c++
here is my code but i simulated using keil with protues Vsm but still cant read anything on my SBUF.

Code:
#include <reg51.h>
#include<string.h>
#include <stdio.h>


void init()
{
EA=0;
TL1=0XFD; //9600 @ 11.0592
TH1=0xFD;
TMOD=0x21;
SCON=0x50;
ET0=1;
TR1=1;
RI=0;
}

void SMSString(char*text) //function to send SMS using GSM modem
{
int count = 0;
while (text[count])
{
tx0(text[count++]);
}
}
void tx0(unsigned char x) //send data to serial port 0
{
while(TI==0){;}
TI=0;
SBUF=x;
}

unsigned char Rx_data( ) // returns data take note
{

while(!RI);//waits till a byte is recieved
RI = 0;
return(SBUF);

}

void main ()
{
P1=0x00;

init();

SMSString("AT\r"); // AT commands to initialize gsm modem

delay_sms(1000);
SMSString( "ATe0\r"); // turn off echo
delay_sms(1000);
SMSString( "AT&W\r"); // save settings
delay_sms(9000);
sSMSString( "AT+CMGF=1\r"); // select text mode for sms
delay_sms(90000);
SMSString( "AT+CNMI=2,1,0,0,0\r"); // notification of new sms
delay_sms(90000);
SMSString( "AT+CMGR=1\r"); // AT command to read sms

/* i get a response like this
// +CMGR:"REC READ"," +95445677888 begin_of_the_skype_highlighting              +95445677888      end_of_the_skype_highlighting", "Date and time", sms text here
// Ok. */

// read sms and store in buffer msg1

for(j=0;j<100;j++)
msg1[j] = Rx_data(); // stroring data in buffer for string compare.
delay_sms(9000);

i am using Protues with compim interfaced with gsm modem on the serial port.
i am able to send sms via protues but cant receive and extract sms.
 

You may try this logic (something like this) for copy data ("sms text here") from received buffer (msg1) "+CMGR:"REC READ", "+2347060580383" "Date and time", sms text here"

Code:
i = strrpos (msg1, ',');
for (k=i;k<sizeof(msg1);k++)
msg2[k2] = msg1[k];
k2++;
then print msg2[]

For reference
Cx51 User's Guide: strrpos Library Routine
 

You may try this logic (something like this) for copy data ("sms text here") from received buffer (msg1) "+CMGR:"REC READ", "+2347060580383 begin_of_the_skype_highlighting**************+2347060580383******end_of_the_skype_highlighting begin_of_the_skype_highlighting**************+2347060580383******end_of_the_skype_highlighting begin_of_the_skype_highlighting**************+2347060580383******end_of_the_skype_highlighting" "Date and time", sms text here"

Code:
i = strrpos (msg1, ',');
for (k=i;k<sizeof(msg1);k++)
msg2[k2] = msg1[k];
k2++;
then print msg2[]

For reference
Cx51 User's Guide: strrpos Library Routine

@bassa,
i have been trying your code above but am not getting anything and i keep getting compiler error,this is the response from my AT command to read sms message from modem,

+CMGR: "REC UNREAD" ,"+2347060580383","10/10/27,18:54:32+04"
Wellcome To University of Nigeria Nsukka,Department of Electronic Engineering.

OK

thanks for your anticipated reply
 

I suggested a method (not a exact code) to extract SMS message for received string as you mentioned in your first post as +CMGR:"REC READ", "+2347060580383" "Date and time", sms text here

first you need to identify the position of last "," character then you need to copy the characters, starting form that position onwards until the end of sting (sizeof string)

But you second message, it is not mentioned (last "," character)

+CMGR: "REC UNREAD" ,"+2347060580383","10/10/27,18:54:32+04"
Wellcome To University of Nigeria Nsukka,Department of Electronic Engineering.

Anyway you need to identify the starting position and then extract the required message
 

should you store the every data received, for example the "+","C","M","G"....... into A,then rotate it using counter while decrement it(the counter probably around 56,since there are 56 character there including spacebar untill ....."+","0","4"). haven't tried it yet but just to give u the idea and to discuss if it can work?i believe the read message got 56-57 chracter everytime u send the AT+CMGR=1 command

well im having the problem of sending the message, i did coding for AT+CMGF=1,AT+CMGS=xxxx<enter> message <Ctr+Z> but it didn't send the message, i gladly would share some of my coding but i'll not post it here. students getting lazy to go n study by themselves bout this coding,always asking and not sharing -.-"
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top