View previous topic :: View next topic |
Author |
Message |
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue May 05, 2015 5:33 pm |
|
|
To search for the unknown string, first confirm you have a known string like "PHONE" in your example.
Then search the buffer individually for a O then an N and finally an E... if the conditions are met you are now standing at the beginning of your desired string.... after doing the above you now know exactly the index number of where in your buffer your desired string starts.... then just copy it one by one to your variable/temp string.
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
creative_35
Joined: 02 Jan 2007 Posts: 15
|
|
Posted: Wed May 06, 2015 8:07 am |
|
|
Thanks Gabriel for the instant reply, I wrote the code as follows
Code: | char *p;
p= strchr(Receive_String,'H');
if ((p+1)==strchr(Receive_String,'O')||(p+2)==strchr(Receive_String,'N')||(p+3)==strchr(Receive_String,'E'))
int k = p-Receive_String+4;
strncpy(SAVED_NUMBER,Receive_String+k,10);
fprintf (TERMINAL,"\r%s\n",SAVED_NUMBER); |
Is is working, But I have to change the "SIZE_BUFFER" value to 90 and it's almost full the "RAM".
returning error If I change above 96 !!
(*** Error 74 "gsmtest.c" Line 178(1,2): Not enough RAM for all variables)
Any Idea to skip the first half portion of the message to reduce the BUFFER size? Thank you, |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Wed May 06, 2015 8:19 am |
|
|
Remember that your message might include more than one 'H' so you need to keep checking the buffer for the "HONE" string until the end of buffer.
Else if you find an unrelated 'H' the subsequent IFs will fail even if the correct message is further down the buffer.
I've tried numerous ways of skipping the first part of the message and ive found it to be very impractical cause you lose a lot of information, you have to include stuff in you ISR. It is also very dependent on your PIC speed.
Doing string searches on the buffer that is still being filled might not yield good results... not impossible but cumbersome (IMO).
Mi current buffer is 255 chars long... considering SMS has a limit of 140 (160?) chars + the system info included by the modem. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
samuel
Joined: 04 May 2016 Posts: 14
|
|
Posted: Tue May 10, 2016 6:01 am |
|
|
Hello!
please what can i change in the main program if i should use pic16f877
because i tried including pic16f877a i receive error
Quote: | undefined identifier CCP_PULSE_STEERING_A |
|
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue May 10, 2016 1:57 pm |
|
|
Hi,
Just comment these two lines out:
Code: |
setup_ccp1(CCP_PWM|CCP_PULSE_STEERING_A); // Configure CCP1 as a PWM
set_pwm1_duty(416L); // Set Duty to %50 (Drives LCD -Ve pump)
|
These are specific to MY hardware LCD which required a -Ve....
Most modern LCDs do not need this.
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
LazBoy
Joined: 17 Oct 2006 Posts: 8
|
|
Posted: Wed Jun 08, 2016 9:58 am |
|
|
Thank you Gabriel for your great driver.
I want to share my FLASH SMS routine based on mentioned driver
as follows:
Code: |
void FLASH_SMS(char *GSM_Num,char *SMS_Mes)
{
counter_read=0;
printf("AT+CSMP=17,167,0,16\r"); // FLASH SMS Mode
DELAY(5);
counter_read=0;
printf("AT+CMGS=");
printf(GSM_Num);
printf("\r");
DELAY(5);
counter_read=0;
printf("ALARM! condition triggered.\rCheck SMS messages.\r");
putchar(0x1A);
while(STRING_SEARCH(OK)==0){}
counter_read=0;
printf("AT+CSMP=17,167,0,0\r"); // Normal SMS Mode
DELAY(5);
counter_read=0;
printf("AT+CMGS=");
printf(GSM_Num);
printf("\r");
DELAY(5);
counter_read=0;
printf(SMS_Mes);
putchar(0x1A);
DELAY(50);
}
|
|
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Wed Jun 08, 2016 11:15 am |
|
|
Hey thanks for the addition!
I didn't know they were called flash sms!
I'll surely add this to my bag of tricks!
awesome share man!
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
samuel
Joined: 04 May 2016 Posts: 14
|
interfacing GSM module and Pic |
Posted: Sun Aug 14, 2016 8:59 am |
|
|
Hello!!!
Please creative_35 you said you tested it with SIM900 and it worked. I wish to know how you connected the GSM module to the pic. Was it direct or did you interface it with another IC ?
I am using SIM900A.
Thanks |
|
|
samuel
Joined: 04 May 2016 Posts: 14
|
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Mon Sep 05, 2016 3:55 pm |
|
|
how are your connections made?
is your modem TX/RX 5V or 3.3V or RS232
this driver was made with a modem working at 115Kbps, what baud is your modem using?
this driver was tested with a 16F886 which is pretty much the same as the '877A but you need to change one or two things.
are you simulating or using real hardware?
are you sure your connections are right?
are you using an LCD screen? what does it say?
This driver is very verbose and it literally tells you what is wrong, if you have an LCD connected as per PCM_Programmers FLEX_LCD driver.
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
samuel
Joined: 04 May 2016 Posts: 14
|
|
Posted: Tue Sep 06, 2016 4:39 am |
|
|
thank you very much for your reply
on that GSM module there are three sets of pins,
3VR and 3VT
5VR and 5VT
GND and VCC_MCU
i am using the pair of 5VR and 5VT
5VR ---->MCU TX
5VT -----> MCU RX
I am implementing it on hardware not simulation.
this is what the LCD screen is showing:
COMMS FAILED
RETRYING - STUCK
Code: |
#include <16F877A.h>
#device ADC=8
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NODEBUG
//#FUSES NOWDT //No Watch Dog Timer
//#FUSES NOBROWNOUT //No brownout reset
#define LCD_ENABLE_PIN PIN_D3
#define LCD_RS_PIN PIN_D1
#define LCD_RW_PIN PIN_D2
#define LCD_DATA4 PIN_D4
#define LCD_DATA5 PIN_D5
#define LCD_DATA6 PIN_D6
#define LCD_DATA7 PIN_D7
#use delay(crystal=20000000)
#include <lcd.c>
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//#include "servos.c"
#include "string.h"
#include "gsm.c"
//#include "servos.c"
#include "servofunctions.c"
void main()
{
//init_servos();
int value=5;
lcd_init();
lcd_putc("\fReady...\n");
delay_ms(1000);
int sms_index=1;
//enable_interrupts(int_rb);
//ENABLE_INTERRUPTS(GLOBAL); // Enable Interrupts
// ENABLE_INTERRUPTS(INT_RDA); // Enable Serial Interrupts
// lcd_init(); // Initialize LCD Screen
//**************************************************************************
// Clears the Comm buffer
//**************************************************************************
lcd_putc("\fyou are welcome\n");
CLEAR_BUFFER();
lcd_putc("\fBUFFER CLEARED\n");
DELAY(1); // Delay a maximum of X seconds
while(1)
{
//**************************************************************************
// Check if modem is attached
//**************************************************************************
if(CHECK_COM())
{
CLEAR_BUFFER();
lcd_putc("\fCOMMS ARE GOOD\n");
lcd_putc("\MOVING ON...\n");
DELAY(1); // Delay a maximum of X seconds
}
else
{
lcd_putc("\fCOMMS FAILED\n");
DELAY(1); // Delay a maximum of X seconds
while(!CHECK_COM())
{
lcd_putc("\RETRYING - STUCK IN LOOP\n");
DELAY(1); // Delay a maximum of X seconds
}
lcd_putc("\f");
lcd_putc("\fCOMMS ARE GOOD\n");
}
DELAY(1); // Delay a maximum of X seconds;
//**************************************************************************
// Set Modem to TXT mode
//**************************************************************************
lcd_putc("\fSET MODEM TO TXT MODE\n");
DELAY(1); // Delay a maximum of X seconds
if(SET_PDU())
{
CLEAR_BUFFER();
lcd_putc("\OK! - MOVING ON...\n");
DELAY(1); // Delay a maximum of X seconds
}
else
{
lcd_putc("\ERROR - STUCK IN LOOP...\n");
while(1);
}
//**************************************************************************
// Set Prefered message Storage
//**************************************************************************
lcd_putc("\fSETTING SMS MEMORY\n");
DELAY(1); // Delay a maximum of X seconds;
if(SET_MEM())
{
CLEAR_BUFFER();
lcd_putc("\OK! - MOVING ON...\n");
DELAY(1); // Delay a maximum of X seconds
}
else
{
lcd_putc("\ERROR - STUCK IN LOOP...\n");
while(1);
}
//**************************************************************************
// Set SMS Alert Message
//**************************************************************************
lcd_putc("\fSETTING SMS ALERT\n");
DELAY(1); // Delay a maximum of X seconds;
if(SET_CNMI())
{
CLEAR_BUFFER();
lcd_putc("\OK! - MOVING ON...\n");
DELAY(1); // Delay a maximum of X seconds
}
else
{
lcd_putc("\ERROR - STUCK IN LOOP...\n");
while(1);
}
//**************************************************************************
// WAIT FOR SMS AND READ
//**************************************************************************
lcd_putc("\fMODEM SETUP IS DONE\n");
lcd_putc("\CLEARING BUFFER...\n");
CLEAR_BUFFER();
lcd_putc("\DONE ---> RUN PROGRAM\n");
DELAY(1); // Delay a maximum of X seconds
while(1)
{
int value = 5;
lcd_putc("\f");
lcd_putc("\fsending message\n");
CLEAR_BUFFER();
SEND_SMS();
DELAY(3); // Delay a maximum of X seconds
DEL_SMS(sms_index); //delete the received sms to create romm for further sms
sms_index++; //
CLEAR_BUFFER();
}
}//--END OF MAIN WHILE
}
|
|
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue Sep 06, 2016 9:32 am |
|
|
Hi, the LCD display is telling you what the problem is.
Your PIC is not communicating properly with the modem.
the pic is sending the "AT" command and looking for the "OK" response..
its not getting it.
1) check TX/RX connections (try swapping the TX/RX pins)
2) check your modem/PIC baud rate
can you set up a terminal and see what the pic is sending or what the modem is responding by snooping the TX/RX lines?
G. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
samuel
Joined: 04 May 2016 Posts: 14
|
|
Posted: Wed Sep 07, 2016 1:59 pm |
|
|
hello Gabriel!
these are some things i did.
1) i connected the GND of module to GND of pic
2)i simply put the sent function in a while loop without checking communication with the AT command and i could transmit
so it means the problem was as you said, the pic was not receiving an ok so it got stucked.
However though i can't still understand why, I think I am at 30% on the go
the next part which is the receiving i will try it tomorrow in the lab.
thanks!!! |
|
|
samuel
Joined: 04 May 2016 Posts: 14
|
|
Posted: Thu Sep 15, 2016 4:34 am |
|
|
thank you very much Gabriel
i was trying to modify the code without first testing yours. after testing the sample code it worked. so i have to continue from there. but i have a worry
when an SMS arrives, it displays SMS RECEIVED however it stays there almost for 3 minutes before coming back to WAITING FOR SMS .
i cannot figure out why.
once more thanks for this powerful GSM driver and code. |
|
|
xoom
Joined: 18 Nov 2016 Posts: 4
|
|
Posted: Fri Nov 18, 2016 8:26 am |
|
|
Quote: | while(1)
{
lcd_putc("\f");
lcd_putc("\fWAITING FOR SMS\n");
while(!STRING_SEARCH(CMTI)){}
lcd_putc("\fSMS RECEIVED!!!\n");
CLEAR_BUFFER();
sms_index=1;
while(READ_SMS(sms_index))
{
if(GET_SMS_COMMAND()==AIRE)lcd_putc("\PRENDE AIRE\n");
if(GET_SMS_COMMAND()==LUZ1)lcd_putc("\PRENDE LUZ 1\n");
if(GET_SMS_COMMAND()==LUZ2)
{
lcd_putc("\PRENDE LUZ 2\n");
CLEAR_BUFFER();
SEND_SMS();
}
DELAY(3); // Delay a maximum of X seconds
DEL_SMS(sms_index);
sms_index++;
CLEAR_BUFFER();
} |
what sms sentence should i write to activate the SEND_SMS(); sentence above? pls
@Gabriel |
|
|
|