CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

sms read from gsm module

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ILLIAS28



Joined: 11 Jan 2011
Posts: 42

View user's profile Send private message

sms read from gsm module
PostPosted: Sun Feb 25, 2018 11:46 am     Reply with quote

Could you please help me ?
I am interfacing a gsm module sim800l with pic18f252 in order to receive sms, read it, decode it and control some devices. Everything is ok for short messages, but it doesn't work for long messages. Here is the message i want to receive
[img]https://ibb.co/h5WDnc [/img]
I have tried to read it and parse it but I only get the first 212 characters. Can someone help me to resolve this problem? Here is the code i have written to read and display on a 2x16 lcd, line by line (16 characters at a time).
Thank you very much.
Code:

#include <18F252.h>
#device PASS_STRINGS=IN_RAM
#fuses HS,NOWDT,PUT,NOPROTECT,NOBROWNOUT,NOLVP,NOCPD,NODEBUG
#use delay(clock=16000000)
#use rs232(baud=57600,UART1,BITS=8,XMIT=PIN_C6,RCV=PIN_C7,PARITY=N,STOP=1,ERRORS)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define use_portb_lcd TRUE
#include <lcd.c>
#byte PortA = getenv("SFR:PORTA")
#byte Portc = getenv("SFR:PORTC")


int ndxint,a,poussoir;
char *reponse , buffer[694],test[18],stTemp[2],buf[695];
unsigned char ndxcar=0;
long i,j,k;

#INT_RDA
void SerialInt()

  buffer[i]=getchar(); 
       
   i++;
}

//!//initialisation et configuration gsm
//__________________________________________________________________
void main()
{
i=0;
j=1;
k=0;
a=0;
SET_TRIS_A(0x00);
SET_TRIS_B(0x00);
SET_TRIS_C(0xFF);


PORTA=0x00;
DELAY_ms(1000);
lcd_init();
 
lcd_putc('\f');
printf(lcd_putc,"salut");
DELAY_ms(1000);
 i=0;
   reponse=NULL; 
   memset(buffer,NULL,694);
   memset(buf,NULL,694);
ENABLE_INTERRUPTS(GLOBAL);               // Enable Interrupts
ENABLE_INTERRUPTS(INT_RDA);
DELAY_ms(3000);   
      reponse=NULL;     
      lcd_putc('\f');
      printf(lcd_putc,"connecting...");
      DELAY_ms(1000);   
 
      do {
      printf("at\r");
      DELAY_ms(200);     
      reponse=strstr(buffer,"OK");//test if gsm is responding
      }while (reponse == NULL);
       memset(buffer,NULL,694);           
           lcd_putc('\f');         
           printf(lcd_putc,"configuring GSM");    //if response is "ok" display "configuring gsm" on lcd and configure gsm   
           DELAY_ms(1000);
         
            printf("AT+CMGF=1\r");   
            DELAY_ms(5000);
            memset(buffer,NULL,694);
          printf("AT+CPMS=\"SM\",\"SM\",\"SM\"\r");
           DELAY_ms(5000);
           memset(buffer,NULL,694);
            printf("AT+CMGD=1,4\r");
            DELAY_ms(5000);
             printf("AT+CMGDA\r");
            DELAY_ms(7000);
            memset(buffer,NULL,694);
           printf("AT+CNMI=2,1,0,0,0\r");
            DELAY_ms(7000);
            memset(buffer,NULL,694);
   i=0;
   reponse=NULL; 
   memset(buffer,NULL,694);
   memset(buf,NULL,694);

//attente sms
//__________________________________________________________________________
for(;;)
 
 {   
               lcd_putc('\f');       
               printf(lcd_putc,"WAITING FOR SMS");
               DELAY_ms(2000);
               
               do
               {
               reponse=strstr(buffer,"+CMTI");//detect reception message

               }while(reponse == NULL);
               
      lcd_putc('\f');
                printf(lcd_putc,"%li",i);
                 DELAY_ms(5000);
               strncpy(test,reponse,13);
               test[13]='\0';
               lcd_putc('\f');
               printf(lcd_putc,test); //display reponse a la reception sms on lcd(+CMTI:"sm",1)
               DELAY_ms(2000);
//extraire index sms
//___________________________________________________________________________
               ndxcar=test[12];
               sprintf(stTemp,"%c",ndxcar);
               ndxint = atoi(stTemp);
               lcd_putc('\f');
               lcd_putc(ndxCAR);
               DELAY_ms(2000);
               i=0;
               memset(buffer,NULL,694);
               DELAY_ms(1000); 
              DELAY_ms(1000);

//read and display sms
//_____________________________________________________________________________
           lcd_putc('\f');       
               printf(lcd_putc,"reading sms");
               printf("AT+CMGR=%d\r",ndxint);
               DELAY_ms(10000);
               lcd_putc('\f');
                printf(lcd_putc,"%li",i);
                 DELAY_ms(5000);
               do
               {
               reponse=strstr(buffer,"(25");//detect begin of message
               }while(reponse == NULL);
                strncpy(buf,reponse,520);
                buf[521]='\0';
                lcd_putc('\f');
               for(j=1;j<=520;j++)
               
               {
                 if(j%3==0)
                     j++;
                test[a]=buf[j];
                a++;
                if(a==16)
                  {
                   
                    printf(lcd_putc,test);
                   
                    do
                     {
                      poussoir=(portc & 0x01);
                      DELAY_ms(300);
                     }while (poussoir==0);
                     a=0;
                    k++;
                    if(k==2)
                    {
                    lcd_putc('\f');
                    k=0;
                    }
                    else{lcd_putc('\n');}
                  }
                 
               }
               j=1;
               a=0;
               

//!//effacer sms
//!//_____________________________________________________________________________
                  i=0;
                  lcd_putc('\f');
                   printf(lcd_putc,"erasing sms" );
               printf("AT+CMGD=%d\r",ndxint);
               DELAY_ms(6000);
               reponse='\0';
               memset(buffer,NULL,694);             
               memset(buf,NULL,694);
               DELAY_ms(1000);
               i=0;
  }
 } 

_________________
i am newbe
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sun Feb 25, 2018 12:07 pm     Reply with quote

It's probably not totally your code (use the code buttons...).

What is the limit on length for an SMS message?. It varies with IP's, but used to be 160 characters, anything longer was sent as multiple messages of 153 characters. This was why Twitter had the limit at 140 characters (they use 20). It has now been extended, but it is unwise to actually rely on a message being longer than this.

However your serial interrupt code is flawed. I'm surprised it works at all.
ILLIAS28



Joined: 11 Jan 2011
Posts: 42

View user's profile Send private message

PostPosted: Sun Feb 25, 2018 1:16 pm     Reply with quote

thank you for your response Ttelmah,
i didn't understand what do you mean with"use the code buttons".
but why i receive the full message on my smartphone?
is there a solution for this problem?
thank you once again

++++++++++++++
Code block added.

- Forum Moderator
++++++++++++++

_________________
i am newbe
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sun Feb 25, 2018 1:19 pm     Reply with quote

When posting code, use the Code button before the code, and then the button again afterwards. Otherwise it becomes almost unreadable.
Your phone will automatically assemble the multiple messages. You are going to have to do the same.
ILLIAS28



Joined: 11 Jan 2011
Posts: 42

View user's profile Send private message

PostPosted: Sun Feb 25, 2018 3:57 pm     Reply with quote

ok i have understand, and thank you very much
_________________
i am newbe
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 25, 2018 4:43 pm     Reply with quote

Another way to do code blocks is to highlight all your code with the
mouse. Hold down your left mouse button and sweep your mouse
over your code to highlight it. Then press the code button once.
This will put the Code and /Code markers at the start and end of the block.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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