PDA

View Full Version : Receiving message to PIC through GSM modem



andymuller
- 26th April 2014, 19:05
Hello every one,

Can someone help me please? I have tried few ways but I can’t make it to work. I should add, I can send & receive sms as well. Even I can view received sms on lcd. But, I am not sure how I can proceed a text message from the GSM such as a command like: "LED1ON" and switch LED1 on.

Many thanks in advance.

All suggestions are welcome

pedja089
- 26th April 2014, 19:19
http://www.picbasic.co.uk/forum/showthread.php?t=2728&p=117009#post117009

andymuller
- 27th April 2014, 07:41
Hello Pedja,

Thank you in advance for your help and support.
I read whole of this link:

http://www.picbasic.co.uk/forum/showthread.php?t=2728&p=117009#post117009

I have used the array for reading from serial in. As I already said, I can show the received message on LCD. so it means arrays work well.
Here is my simple sample. In this routine my GSM modem (SIM900) even detects the right temperature and shows it on LCD as well. But still I can not control a simple LED throu it .

Would you please help?


@ device hs_osc
define osc 20
DEFINE CHAR_PACING 10
include "modedefs.bas"
'-------------------------------------------------------------------------------
i var byte
s var byte[90]
n var byte[90]
'-------------------------------------------------------------------------------
trisb=0
portb=0
trisc=%10000010
portc=0
trisa=0
porta=0
'-------------------------------------------------------------------------------
define lcd_dreg portb
define lcd_dbit 4

define lcd_rsreg portb
define lcd_rsbit 1

define lcd_ereg portb
define lcd_ebit 0

define lcd_bits 4
define lcd_lines 2

lcdout $fe,$01
'-------------------------------------------------------------------------------
cr con 13
cz con 26
cot con 34
space con 32
comma con 44
'################################################# ##############################
clear
high portb.3 'Switching ON"
lcdout $fe,$01
lcdout $fe,128,"Power-UP....",#i
pause 1200
lcdout $fe,128,"Power released"
low portb.3

pause 10000
'************************************************* *******************************
ini:
clear
lcdout $fe,$01
for i=0 to 4
serout portc.6,T9600,["AT",cr]
pause 1000
lcdout $fe,128,"Initialize ",#i
next i
serout portc.6,T9600,["AT+CMGF=1",cr]
pause 1000
serout portc.6,T9600,["AT+CMGDA=",cot,"DEL",space,"ALL",cot,CR] '* DELETE all message
pause 1500
lcdout $fe,1

serout portc.6,T9600,["AT+CMTE?",cr]
serin portc.7,T9600,1000,ini,["+CMTE:"],n(24)
for i=25 to 29
serin portc.7,T9600,1000,ini,n(i)
next i
LCDout $fe,192,"Temp=",n(27),n(28),223,"C"

PAUSE 1000


start:
if portc.1=0 then

for i=30 to 42
serin portc.7,T9600,1000,start,n(i)
next i
if ( n(33)="C" and n(34)="M" and n(35)="T" and n(36)="I") then
lcdout $fe,1
lcdout $fe,128,"Reading"
pause 1000
serout portc.6,T9600,["AT+CMGR=",n(42),cr]
serin portc.7, T9600,5000,w2,["+CMGR:"],s(0)
for i=1 to 84
serin portc.7, T9600,1000,w2,s(i)
next i

endif
endif
if (s(59)="S") then
high portc.3
s(59)=0
endif
if(s(59)="T" and s(60)="a") then
low portc.3
s(59)=0
s(60)=0
endif
lcdout $fe,1
lcdout $fe,128,s(59),"s59",#s(59)
lcdout $fe,192,s(59),s(60)," 59-60-END" ;for myself understanding and tracing on datas on LCD

serout portc.6,T9600,["AT+CMGD=",n(42),comma,4,cr]
pause 1000
goto start
'************************************************* *******************************

'************************************************* *********************************

w2:
pause 5000
serout portc.6,T9600,["AT+CMGR=",n(42),cr]
serin portc.7, T9600,5000,ini,["+CMS ERROR:"],s(87),s(88),s(89)
pause 5000
lcdout $fe,01
lcdout $fe,128,"SMS receiving"
lcdout $fe,192,"Error=",s(87),s(88),s(89)
pause 2000
goto start
'************************************************* *************************************************
END

pedja089
- 27th April 2014, 12:42
Did you see this?

CommandParser:
; Fast searcher! Case sensitive. Closely based on info provided by Darrel Taylor.
; Searches through Str1. If it finds the strings listed in the quotes, it returns which one it found.
; the max length of STR1 that will be searched is in MaxSearchLen

Cmd = 255 ; In case of no match
MaxSearchLen = 20

Parse01: Cmd=01 : ARRAYREAD Str1,MaxSearchLen,Parse02,[WAIT("LedOn")] : GOTO Foundit
Parse02: Cmd=02 : ARRAYREAD Str1,MaxSearchLen,Foundit,[WAIT("LedOff")] : GOTO Foundit
Foundit:
return
Use STR modifier to receive string from modem into array Str1. Then call parser and check Cmd, if Cmd=1 then led on, if Cmd=2 then led off.

andymuller
- 29th April 2014, 07:35
Hello Pedja,

Thank you for your support.

I am not sure if my compiler (PicbasicPro 2.6) supports "ARRAYREAD".

pedja089
- 29th April 2014, 08:25
Then try it... And you will find out ;)

andymuller
- 29th April 2014, 08:38
Thank you:)

EarlyBird2
- 29th April 2014, 10:15
Have you set new message notification? It is not in your code.

andymuller
- 30th April 2014, 07:40
Have you set new message notification? It is not in your code.

Hello Bird,

Yes, there is a pin on sim900 GSM modem, if a new message be received this pin will be in high state less than 1 second, I use this pin for the new message notification. But i didn't use this feature in this sample routine. Because I am still busy with comparing two things with each other... the question of this thread is still valid ;)

Thank you

EarlyBird2
- 12th June 2014, 10:44
Is this the code that does the comparison?



if (s(59)="S") then
high portc.3
s(59)=0
endif
if(s(59)="T" and s(60)="a") then
low portc.3
s(59)=0
s(60)=0
endif


and needs modifying to "LED1ON" and "LED1OFF" but does not work even with the simple test of "S" and "Ta"?

andymuller
- 18th June 2014, 17:27
Hello Steve,

Thanks a lot for your posting here.

I apologize. I was late in reply

Yes, it is, it compares incoming message with a pattern and chooses what commands must run. here is just simple put a pin on high or low states.

Do you have any other suggestion for comparing?

Thank you

EarlyBird2
- 19th June 2014, 08:28
Is this the code that does the comparison?



if (s(59)="S") then
high portc.3
s(59)=0
endif
if(s(59)="T" and s(60)="a") then
low portc.3
s(59)=0
s(60)=0
endif


and needs modifying to "LED1ON" and "LED1OFF" but does not work even with the simple test of "S" and "Ta"?

Does this work?