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.

AT commands:Extracting sender ID and time stamp from SMS

Status
Not open for further replies.

ulrikp

Junior Member level 3
Joined
Mar 1, 2010
Messages
31
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
Copenhagen
Activity points
1,568
Hi,

I'm making a door alarm using a GPRS module. An example of an SMS looks like this:

+CMGR: "REC UNREAD", "+4588888888", "", "10/03/29,11:08:41+04"
Message here...

Now, I would like a bulletproof way to extract the sender ID and time stamp, but I cannot find the AT commands for this. Right now, I'm counting the "/+/: characters and thereby getting the data I need, but I imagine there is better a way that will catch any phone number length and any country code format.

Thanks,
Ulrik
 

It's a comma delimited string...each field is seperated by commas. The typical way to parse the data is to search the string for the commas the are just before and just after the field you want. You can use the "strtok" function to tokenize the data, or the "strchr" function to find the commas.
 

    ulrikp

    Points: 2
    Helpful Answer Positive Rating
hey ulrikp , i need the same thing in my prj GSM based vehicle tracking. i wrote a code for this but cudnt get the sender's number

plz post ur code or PM me so that i could find logical mistake made by me
plz do reply

im also sending my code as a ref so that may find any mistake in it

Added after 23 seconds:

// ***********************************************************
// Project:
// Author:
// Module description:
// ***********************************************************

#include <avr\io.h> // Most basic include files
#include <avr\interrupt.h> // Add the necessary ones
#include <avr\signal.h> // here
#define F_CPU 1000000UL
#include<util\delay.h>
// Define here the global static variables
//
void USART_Init( unsigned int); //prototype for Intialization function
void USART_Transmit( unsigned char); //prototype for data Transmitting
// function with one input argument
unsigned char USART_Receive( void ); //prototype for data Recieving function


// ***********************************************************
// Main program
//
int main(void) {
DDRB=0xff;

int baud=12; //loading 12 in UBBR i.e baudrate=9600
//intializing variables
// unsigned char device;

int flag=0;
unsigned int i=0;

unsigned char r_data,l=26;

USART_Init(baud);
for(i=0; i<65535; i++);
for(i=0; i<65535; i++);
USART_Transmit('A');
USART_Transmit('T');
USART_Transmit(' \r');
USART_Transmit('\n');
for(i=0; i<65535; i++);
USART_Transmit('A');
USART_Transmit('T');
USART_Transmit('E');
USART_Transmit('0');
USART_Transmit('\r');
USART_Transmit('\n');
for(i=0; i<65535; i++);
USART_Transmit('A');
USART_Transmit('T');
USART_Transmit('+');
USART_Transmit('C');
USART_Transmit('M');
USART_Transmit('G');
USART_Transmit('F');
USART_Transmit('=');
USART_Transmit('1');
USART_Transmit('\r');
USART_Transmit('\n');
for(i=0; i<65535; i++);


flag=1;



while(1) { // Infinite loop; define here the
/* USART_Transmit('A');
USART_Transmit('T');
USART_Transmit('+');
USART_Transmit('C');
USART_Transmit('M');
USART_Transmit('G');
USART_Transmit('R');
USART_Transmit('=');
USART_Transmit('1');
USART_Transmit('\r');
USART_Transmit('\n'); */
r_data= USART_Receive();
if(flag==1 && r_data=='+')
{

for(i=0; i<65535; i++);
USART_Transmit('A');
USART_Transmit('T');
USART_Transmit('+');
USART_Transmit('C');
USART_Transmit('M');
USART_Transmit('G');
USART_Transmit('S');

USART_Transmit('=');
USART_Transmit('"');
USART_Transmit('+');
USART_Transmit('9');
USART_Transmit('2');
USART_Transmit('3');
USART_Transmit('3');
USART_Transmit('1');
USART_Transmit('5');
USART_Transmit('5');
USART_Transmit('3');
USART_Transmit('9');
USART_Transmit('3');
USART_Transmit('4');
USART_Transmit('7');
USART_Transmit('"');
// USART_Transmit(no[14]);


USART_Transmit('\r');
USART_Transmit('F');
USART_Transmit('A');
USART_Transmit('D');

USART_Transmit(l);
for(i=0; i<65535; i++);
PORTB=0xAA;

}

}



}



void USART_Init( unsigned int baud ) //defining intialization function
{


UBRRL = baud; //sending value in UBRRL i.e
UCSRA |= (1<<U2X); // Setting baud rate=9600
UCSRB |= (1<<RXEN)|(1<<TXEN); // Enabling receiver and transmitter bits
UCSRC |= (1<<URSEL)|(0<<USBS)|(3<<UCSZ0)|(0<<UPM0);
//Setting frame format:
//8data bits, 1stop bits, no parity




}
// ***********************************************************
void USART_Transmit( unsigned char data ) //defining data transmitting function
{
//flag=1;
while (( UCSRA & (1<<UDRE))==0 /*&& flag==0*/) ;//Wait until the transmitter buffer gets
//empty
UDR = data; //Putting data into buffer, sending the
//flag=0; // data
}
// ***********************************************************
unsigned char USART_Receive( void ) //defining data recieving function
{
while ((UCSRA & (1<<RXC))==0 ); //Wait until all the data is being received
return UDR; //Get and return received data// buffer
}
// ***********************************************************

Added after 1 minutes:

this is only designed to get a new sms indication that starts with '+'. and send me sms if it gets + in receive data or wait for it
 

fouwad,

As GSM man wrote, the information in the incoming SMS is separated by commas. What I do in order to detect the sender's number is to detect the first and the second comma in the SMS string and then find the numbers inbetween. This should be more stable than a search for "+" since some network providers use "00" instead.

If you want an indication when an SMS has arrived, you can setup your device with "AT+CNMI" and "AT+CSMP". I believe the parameters for these settings depend on your SMS class, so I cannot tell you how to set them. When a new SMS arrives, you will then get

+CMTI:<memory>,<index>

My code is structured for my specific application, so it would not help you to look at it. I hope I understood your problems right.
 

thanx, but the basic structure of sms indication is the same
the modem im using shows +CMTI:<memory>,<index>
by default if a sms is received
my sms sending is working but receiving is not working now im confused whether the problem is in hardware or software
so to test my hardware i need a working software that u alrdy have through any logic
i jst need to chk my hardware.
moreover i can convert ur logic into my specific application
if u can send me the code it will b a great help but if u cannot publish it than its ok
thanx and regards
fouwad
 

I see now. I don't mind sharing my code, but I still don't think there's a chance you can use it, not least because it's written for Arduino (and not in C). The commands that I'm sending to my module are pretty standard:
AT+CPIN="XXXX"
AT+CMGF=1
AT+CNMI=2,1,0,1
AT+CSMP=49,167

The rest of my code is arduino stuff for my specific application. At+CNMI and AT+CSMP you don't need in order to receive a message, but they enable the automatic indication when a new message arrives. You can also check this in hyperterminal using AT+CMGR or AT+CMGL.

I think you should test your hardware with hyperterminal if you haven't already - would be more direct than going through the microcontroller. Also, are you sure that your RX line is working? Btw, which module are you using?
 

i checked my hardware on hyperterminal and it works absolutely fine
i wonder why it is not working for my modem

im using SIMCOM sim300z module for my project

thanx for ur help
 

One problem is you are using "AT+CMGR=1" to retreive the SMS message - which will retieve the message at location '1'. However, the message may not be in location 1. You need to use the command "AT+CMGL" to get a list of messages and their corresponding locations.
 
  • Like
Reactions: lanzky

    lanzky

    Points: 2
    Helpful Answer Positive Rating
im trying to extract the information from the incoming sms
for eg: the number of the sender ,the message received.


plz give me a sample code for that or tell a way to how to do that

plz urgent reply needed
regards
 

hi plz help me i want to know the number of the sender
just only the number

using at commands
tnx
 

for only knowing the number here is the algo
1 keep a chk on incoming AT commands
2 if new sms came then start storing data in a string else keep waiting
3 now store the number in another string by giving index number of first string
4 here u have the number of the sender
 

hmmm can i have a sample code im just newbie hir
tnx
im using pic16f628a
and the message i want to get
 

hi theres no strtok and strchr in microbasic
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top