• AVR Freaks

Hot!Read SMS using SIM900a & Pic18f25q10

Author
karsen
Starting Member
  • Total Posts : 67
  • Reward points : 0
  • Joined: 2012/02/07 01:49:31
  • Location: Bangalore
  • Status: offline
2020/01/09 02:00:36 (permalink)
0

Read SMS using SIM900a & Pic18f25q10

main.c Hi, 
I am trying to read the newly arrived message, and if contains a particular word I turn on the led. 
Hardware connections are ok. because i checked with terminal and pc.
 
But the problem is, the code not even cross this line (toggle the led),  if (UART_Data_Ready()).  
Please help me. 
Thanks 
 
 
post edited by karsen - 2020/01/09 02:07:30
#1

12 Replies Related Threads

    pcbbc
    Super Member
    • Total Posts : 1700
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Read SMS using SIM900a & Pic18f25q10 2020/01/09 04:25:29 (permalink)
    0
    Ignore me...
    #2
    ric
    Super Member
    • Total Posts : 27656
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Read SMS using SIM900a & Pic18f25q10 2020/01/09 04:50:53 (permalink)
    0
    Reduce all this:
    #include<xc.h>

    #include <pic18f25q10.h>
    #include "Configuration_Header_File.h"
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>

    to just
    #include<xc.h>
    #include "Configuration_Header_File.h"

     
    This:
    void main() {

    should be
    void main(void) {


    Why are you doing such an awkward test here?
        if (result = strstr (incoming, "ON"));          // search for string "ON" in incoming and save it in result
        if (memcmp("ON", result, 2) == 0)

    Just do
        result = strstr (incoming, "ON"); // search for string "ON" in incoming and save pointer to it in "result"
        if (result)          // did we find it?




    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    karsen
    Starting Member
    • Total Posts : 67
    • Reward points : 0
    • Joined: 2012/02/07 01:49:31
    • Location: Bangalore
    • Status: offline
    Re: Read SMS using SIM900a & Pic18f25q10 2020/01/09 06:25:16 (permalink)
    0
    ric
     
        if (result = strstr (incoming, "ON"));          // search for string "ON" in incoming and save it in result
        if (memcmp("ON", result, 2) == 0)

    Just do
        result = strstr (incoming, "ON"); // search for string "ON" in incoming and save pointer to it in "result"
     
        if (result)          // did we find it?







     its showing error. 
     
    main.c:160:18: warning: implicit declaration of function 'strstr' is invalid in C99 [-Wimplicit-function-declaration]
    result = strstr (incoming, "ON"); // search for string "ON" in incoming and save pointer to it in "result"
    #4
    karsen
    Starting Member
    • Total Posts : 67
    • Reward points : 0
    • Joined: 2012/02/07 01:49:31
    • Location: Bangalore
    • Status: offline
    Re: Read SMS using SIM900a & Pic18f25q10 2020/01/09 06:38:49 (permalink)
    +1 (1)
    I need to add this 
     
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #5
    karsen
    Starting Member
    • Total Posts : 67
    • Reward points : 0
    • Joined: 2012/02/07 01:49:31
    • Location: Bangalore
    • Status: offline
    Re: Read SMS using SIM900a & Pic18f25q10 2020/01/09 07:10:43 (permalink)
    0
    Hi Ric,
    I did your corrections. I need your help. 
     
    The code is not going to the next step of this line.   if (UART_Data_Ready())
     
    while (1) { 
        if (UART_Data_Ready()) { // If data is received,
            yellow =~ yellow;
        for (i= 0; i < 80; i++) {
          incchar = UART_Read(); // read the received data,
          incoming[i] = incchar;
          }
        result = strstr (incoming, "ON"); // search for string "ON" in incoming and save it in result
        if (result)
        
                   {
                    green =~ green;
                   }
        newmsg = strstr (incoming, "OFF"); // search for string "OFF" in incoming and save it in result
        if (newmsg)
        
                   {
                    red =~ red;
                   }
        }
        }

     
    Thanks 
    #6
    ric
    Super Member
    • Total Posts : 27656
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Read SMS using SIM900a & Pic18f25q10 2020/01/09 12:10:33 (permalink)
    +1 (1)
    karsen
     its showing error. 
     
    main.c:160:18: warning: implicit declaration of function 'strstr' is invalid in C99 [-Wimplicit-function-declaration]
    result = strstr (incoming, "ON"); // search for string "ON" in incoming and save pointer to it in "result"

    Oops, I missed that.
    You do need to #include string.h for the "strstr()" function.
    "memcmp" is also in string.h, but you don't need to use that function.
    Do you really need stdlib.h or stdio.h ?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #7
    karsen
    Starting Member
    • Total Posts : 67
    • Reward points : 0
    • Joined: 2012/02/07 01:49:31
    • Location: Bangalore
    • Status: offline
    Re: Read SMS using SIM900a & Pic18f25q10 2020/01/09 21:37:07 (permalink)
    0
    ric
    karsen
     
     Oops, I missed that.
    You do need to #include string.h for the "strstr()" function.
    "memcmp" is also in string.h, but you don't need to use that function.
    Do you really need stdlib.h or stdio.h ?
     


    no, I don't need the other two functions. 
     
    But the problem is still it's not going to the next step of this line.   if (UART_Data_Ready())
    #8
    ric
    Super Member
    • Total Posts : 27656
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Read SMS using SIM900a & Pic18f25q10 2020/01/09 21:55:26 (permalink)
    +1 (1)
    Presumably that means the PIC thinks it is not receiving anything.
    I don't know what exactly you mean by "Hardware connections are ok. because i checked with terminal and pc."
    WHAT did you check?
    Is the PIC's RX pin toggling when you expect it to be receiving data?
    Can you connect the PC to the same signal, at the same time, to see if it receives anything?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #9
    karsen
    Starting Member
    • Total Posts : 67
    • Reward points : 0
    • Joined: 2012/02/07 01:49:31
    • Location: Bangalore
    • Status: offline
    Re: Read SMS using SIM900a & Pic18f25q10 2020/01/10 00:45:20 (permalink)
    0
    ric
    Can you connect the PC to the same signal, at the same time, to see if it receives anything?
     

    Yes ric. After i changed the code by interrupt based. the code is started receiving. 
     
    What i want to do is, i want to decode the received message and find out the mobile number, and message. 
    but now what happening is decode function is not working. Its not extract mobile number and message. 
     
    here is my code 

    while (1) { 
    status_flag=0;
    if (status_flag==1) { // If data is received,
    yellow =~ yellow ;
    /* for (i= 0; i < 80; i++) {
    incchar = UART_Read(); // read the received data,
    incoming[i] = incchar;
    }


    result = strstr (buff, "Ocelli"); // search for string "ON" in incoming and save pointer to it in "result"
    if (result) // did we find it?
    green =~ green;

    newmsg = strstr (buff, "Sec");
    if (newmsg) red =~ red;

    */

    buffer_pointer = 0;

    while(1)
    {
    if(buff[buffer_pointer]=='\r' || buff[buffer_pointer]== 'n') /*wait till \r\n not over*/
    {
    buffer_pointer++;
    }
    else
    break;
    }

    /* search for 1st ',' to get mobile no.*/
    while(buff[buffer_pointer]!=',')
    {
    buffer_pointer++;
    }
    buffer_pointer = buffer_pointer+2;
    /* extract mobile no. of message sender */
    for(int i=0;i<=12;i++)
    {
    Mobile_no[i] = buff[buffer_pointer];
    buffer_pointer++;
    }

    GSM_Send_Msg("999999999",Mobile_no); //hide my number

    do
    {
    buffer_pointer++;
    }while(buff[buffer_pointer-1]!= '\n');

    int i=0;
    /* display and save message */
    while(buff[buffer_pointer]!= '\r' && i<31)
    {
    USART_TxChar(buff[buffer_pointer]);
    message_received[i]=buff[buffer_pointer];

    buffer_pointer++;
    i++;
    }
    GSM_Send_Msg("88888888888",message_received);   //hide my number
    buffer_pointer = 0;
    memset(buff,0,strlen(buff));

    a=0;
    result = 0;
    memset(buff,0,strlen(buff));
    status_flag=0; /* use for new message arrival */
    }
    }
    }

    void __interrupt() myisr(void) // use this in c99 mode
    {
    if(PIR3bits.RC1IF)
    {

    buff[a] = RC1REG; /* read received byte from serial buffer */
    a++;

    if(RC1STAbits.OERR) /* check if any overrun occur due to continuous reception */
    {
    RC1STAbits.CREN = 0;
    NOP();
    RC1STAbits.CREN=1;
    }
    status_flag=1; /* use for new message arrival */


    }
    }
     



    #10
    ric
    Super Member
    • Total Posts : 27656
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Read SMS using SIM900a & Pic18f25q10 2020/01/10 01:34:31 (permalink)
    +1 (1)
    Here
     if(buff[buffer_pointer]=='\r' || buff[buffer_pointer]== 'n') /*wait till \r\n not over*/

    You missed the "\" in "\n"
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #11
    karsen
    Starting Member
    • Total Posts : 67
    • Reward points : 0
    • Joined: 2012/02/07 01:49:31
    • Location: Bangalore
    • Status: offline
    Re: Read SMS using SIM900a & Pic18f25q10 2020/01/10 07:42:35 (permalink)
    0
    ric
    Here
     if(buff[buffer_pointer]=='\r' || buff[buffer_pointer]== 'n') /*wait till \r\n not over*/

    You missed the "\" in "\n"
     


    yeah. i missed it. 
    after i did this, can't get incoming msg and mobile number. 
    #12
    ric
    Super Member
    • Total Posts : 27656
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Read SMS using SIM900a & Pic18f25q10 2020/01/10 13:45:34 (permalink)
    0
    Did you try single-stepping through your code with the debugger to see where it's getting to?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #13
    Jump to:
    © 2020 APG vNext Commercial Version 4.5