Receiving sms with GSM modem and Pic16f887

Status
Not open for further replies.
Hello

I have an A6 AI Thinker GSM Modem board. I have connected it to a pic16f887 and I can send an sms from it when certain conditions have been met in the PIC.
Now I want to use the same modem for controlling the turning on of an LED upon receiving the message 'ON' or 'OFF'. What is the logic for receiving the sms and comparing the received message to 'ON' or 'OFF' and acting accordingly? I am using MikroC for the compiler.
 
You can post your code and results which would be more interesting that just saying it worked.
Here it is
C:
char incchar;
char incoming[80];
char *result;              // command string search result
int i = 0;

void main() {
     PORTB = 0;
     TRISB = 0;              //RB0 input for interrupt
     PORTD = 0;
     TRISD = 0;                 //PORTD all output
     ANCON0 = 0x00;       // Configure PORTC pins as digital
     ANCON1 = 0x00;       // Configure PORTC pins as digital
     ANCON2 = 0x00;       // Configure PORTC pins as digital

  UART1_Init(9600);               // Initialize UART module at 9600 bps
  Delay_ms(100);                  // Wait for UART module to stabilize
  Delay_ms(2000);
  UART1_Write_Text("ATE0\r\n");   // AT command for Echo OFF
  Delay_ms(1000);
  UART1_Write_Text("AT\r\n");       // test GSM Modem
  Delay_ms(1000);
  UART1_Write_Text("AT+CMGF = 1\r\n");  //convert Sim900 module to text mode
  Delay_ms(1000);
  UART1_Write_Text("AT+CNMI=1,2,0,0,0\r\n"); // setup receiving (now important at this stage)
  Delay_ms(1000);
 

while (1) {                     // Endless loop
    if (UART1_Data_Ready()) {     // If data is received,
    for (i= 0; i < 80; i++)   {
      incchar = UART1_Read();     // read the received data,
      incoming[i]  = incchar;
      }
    if (result = strstr (incoming, "ON"));          // search for string "ON" in incoming and save it in result
    if (memcmp("ON", result, 2) == 0)
    
               {
                         PORTB.F0 = 0x01;

                         PORTB.F1 =0x01;
               }
    if (result = strstr (incoming, "OFF"));          // search for string "OFF" in incoming and save it in result
    if (memcmp("OFF", result, 3) == 0)
             {
                         PORTB.F0 =0x00;
                         PORTB.F1 =0x00;
              }

    }
    }
    }
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…