|
|
View previous topic :: View next topic |
Author |
Message |
idm852
Joined: 09 Apr 2013 Posts: 4
|
read SMS |
Posted: Tue Apr 09, 2013 9:40 am |
|
|
hi
I want to Extract the contents of an sms received by my modem.
I do not control perfectly the PCW compiler for that I can not store characters received RS232 in a table. In fact, I receive this frame which I want to extract the date and sender number and content of SMS. for example, if I receive this frame:
+CMGL: 1,"REC UNREAD","+85291234567",,"07/02/18,00:05:10+32"
Reading text messages is easy.
I want to store the date in a table TD, the time in another table TH and TC content in a table for later use
TD : 07/02/18
TH: 00:05:10
TC: Reading text messages is easy.
Best Regards
|
|
|
idm852
Joined: 09 Apr 2013 Posts: 4
|
|
Posted: Tue Apr 09, 2013 9:57 am |
|
|
I use PIC18F2550 and GL865.
I can communicate with the module for sending and receiving. My problem is that after sending the command "AT + CMGR = 1 \ r" I want to store the received frame in table then use this table to retrieve the date, time and message in the other tables.
Can you help me??????? |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Tue Apr 09, 2013 11:53 am |
|
|
Hi,
It's not that hard to do once you can actually receive the data from the GSM model following the +CMGR command.
I setup two arrays, MSG1 and MSG2, to handle the two lines of data returned from the modem. The returned data actually looks like this:
Code: |
<CR><LF>+CMGR: "REC UNREAD","+19785551212","","11/12/09,09:04:24-20"<CR><LF>
Output 1 On<CR><LF>
|
So, you need to setup a reading loop that is 'aware' of the carriage returns <CR>, and linefeeds <LF> that are part of the data being sent, and then fill the two message arrays accordingly.
Here is part of the code to illustrate my technique:
Code: |
do
{
if(bkbhit)
{
TempChar = bgetc();
if (TempChar == '\r')
iReturnIndex++;
if ((iReturnIndex == 1) && (TempChar != '\r') && (TempChar != '\n'))
{
Msg1[ArrayIndex1] = TempChar;
ArrayIndex1++;
if (ArrayIndex1 > 70)
return; //Msg1 buffer has overflowed, so exit the subroutine!
}
// Code for the 2nd Message array goes here......
} while (iReturnIndex < 4);
|
When this code executes, you'll have the 2 lines of data neatly in two arrays. Also, be sure to do this:
Code: |
// Here we null terminate the two Msg lines from the ADH8066 module
Msg1[ArrayIndex1++] = '\0';
Msg2[ArrayIndex2++] = '\0';
|
That should get you started!
John |
|
|
idm852
Joined: 09 Apr 2013 Posts: 4
|
|
Posted: Tue Apr 09, 2013 3:05 pm |
|
|
bkbhit and bgetc ?
I put them in the code but the PCW Compiler does not accept.
undefined identifier bkbhit
undefined identifier bgetc |
|
|
idm852
Joined: 09 Apr 2013 Posts: 4
|
|
Posted: Tue Apr 09, 2013 3:11 pm |
|
|
My plan is to store the received SMS and send them through a serial link (Xmit: B6, RCV: B7) to the computer in order and with a new layout as the context of the message, and then Date and time finally, the number of the sender.
Here is the core of my code:
Code: |
#include <18F2550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6,rcv=pin_C7, parity=N,STREAM=GSM)
#use rs232(baud=9600, xmit=PIN_B6,rcv=pin_B7, parity=N, STREAM=PC)
#include <string.h>
void main()
{
output_low(PIN_b1);
output_low(PIN_b2);
output_low(PIN_b3);
output_low(PIN_b4);
while(true)
{
output_low(PIN_b1);
output_low(PIN_b2);
output_low(PIN_b3);
output_low(PIN_b4);
delay_ms(1000);
output_high(PIN_b1);
fprintf(PC,"initialisation\r");
delay_ms(1000);
fprintf(GSM,"AT\r");
delay_ms(1000);
fprintf(GSM,"AT+IPR=9600\r");
delay_ms(1000);
output_high(PIN_b2);
fprintf(GSM,"AT+CMGF=1\r");
delay_ms(1000);
fprintf(GSM,"AT+CMGR=1\r");
delay_ms(2000);
Receive();
Send_PC();
}
}
|
|
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Tue Apr 09, 2013 5:43 pm |
|
|
Hi,
I'm sorry, I misunderstood your earlier post and assumed that you were much further along with this project than you apparently are.....
I use a circular buffer to receive incoming data from the GSM modem, and bkbhit and bgetc are part of that code. Have a look at 'ex_sisr.exe' to see how it's done.
You definitely want to put the GSM modem on the hardware serial pot of the PIC, and your PC on a software serial port. You also want to add 'Errors' to the hardware serial port #use rs232 statement.
If some of this does not make sense, search the forum and the CCS provided example programs for the answers before asking here on the forum!
John |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|