PDA

View Full Version : How to decode an SMS which looks like this ...



financecatalyst
- 7th October 2009, 01:37
Hi
I am trying to decode an sms like this:
serout2 tx,baud,["AT^SMGR=1",13]
Serin2 rx,baud,5000,main,[WAIT("REC UNREAD"),SKIP 3, STR num\12, skip 28, STR sms\8]

To send an sms I use:
serout2 tx,baud,["AT+CMGS=",34,"+44xxxxxxxxxx",34,13] ' It works fine when I put an predefined number
Serin2 rx,baud,5000,check,[WAIT(">")] ' then sms and enter

Problem:
I want to send an text to the number from which an sms came, So I tried the above command in the following ways:
serout2 tx,baud,["AT+CMGS=",34,STR num\12,34,13]
serout2 tx,baud,["AT+CMGS=",34,STR num,34,13]

It is not working. Can anyone correct me if I am wrong or advise me an alternative Please.
Thanks

aratti
- 7th October 2009, 07:10
It is not working. Can anyone correct me if I am wrong or advise me an alternative Please.

Use this code:


serout2 tx,baud,["AT+CMGS=",STR num\12,13]

Where:


num[0]="+"
num[1]="4"
num[2]="4"
....................

Al.

financecatalyst
- 7th October 2009, 09:34
Use this code:


serout2 tx,baud,["AT+CMGS=",STR num\12,13]

Where:


num[0]="+"
num[1]="4"
num[2]="4"
....................

Al.

I tried the above way but sorry its not working like this.

aratti
- 7th October 2009, 11:17
I tried the above way but sorry its not working like this.

You can tray with SEROUT which seems working better.




Num var Byte [21]
A0 var Byte

Num[0] = "A"
Num[1] = "T"
Num[2] = "+"
Num[3] = "C"
Num[4] = "M"
Num[5] = "G"
Num[6] = "S"
Num[7] = "="
Num[8] = "+"
Num[20]= 13 ' Last array variable MUST be 13

' The above are the constant value

'From Num[9] to Num[19] load your number
Num[9[] = "4"
Num[10] = "4"
Num[11] = ?? ' etc. etc.


' dial and send the sms using the for next loop
For A0 = 0 to 20
serout Tx,T9600,[Num[A0]] ' Change baud rate as per your need.
Next A0



Al.

financecatalyst
- 7th October 2009, 13:10
Thanks for the input, but to try this can you advise me how to load my number from num[9] to num[19] as I am only aware of loading the number using the following command which starts loading it from num[0] to num[12]:

Serin2 rx,baud,5000,main,[WAIT("REC UNREAD"),SKIP 3, STR num\12, skip 28, STR sms\8]

How can I modify the above syntax to start loading from 9 to 19 & NOT 0 to 12?

Thanks

aratti
- 7th October 2009, 13:22
How can I modify the above syntax to start loading from 9 to 19 & NOT 0 to 12?

Use two arrays, one for serin2 and one for serout

For A0=0 to 11
SecondArray[A0+9]=FirstArray[A0]
next A0

Al.

financecatalyst
- 7th October 2009, 19:29
Hi Aratti
Here is a snapshot of what I have done till now:

num var byte[12]
sum var byte[21]
baud con 188

sum[0] = "A"
sum[1] = "T"
sum[2] = "+"
sum[3] = "C"
sum[4] = "M"
sum[5] = "G"
sum[6] = "S"
sum[7] = "="
sum[21]= 13

Serin2 rx,baud,5000,main,[WAIT("REC UNREAD"),SKIP 3, STR num\12, skip 28, STR sms\8]
checkms:
If sms[0]="d" and sms[1]="e" and sms[2]="a" and sms[3]="c" and sms[4]="t" then
For c=0 to 12
sum[c+8]=num[c]
next c
For c=0 to 21
serout tx,T2400,[sum[c]]
next c
Serin2 rx,baud,5000,checkms,[WAIT(">")]


This arrangement is not working. Can you advise me of whats wrong. Many thanks for your time in advance

aratti
- 7th October 2009, 23:03
In your code you use the byte variable "C" but I don't see it declared.

Did you include "MODEDEFS.BAS" in your code?




num var byte[12]

For c=0 to 12 ' you will need 13 bytes here
sum[c+8]=num[c]
next c

How long is your phone number? You have declared an array (num) of 12 bytes but the for/next loop is trying to use 13 bytes!

Also the array sum is declared for 21 and you are attempting to use 22 (you have sum[21]= 13) This is an array of 22 bytes!
Remember that you have to count also the zero.

So adjust both the arrays as per the lenght of your phone number ( if 13 digits then you need 13 in the declaration and 13 in the string numerical. If on the contrary the phone lenght is 12 digits then modify the for/next loop to For c=0 to 11 and put byte array sum var byte[22]


Al.

financecatalyst
- 7th October 2009, 23:23
Hi
My number length is +447832225144 (0-12)(or 13 if counted from 1)

I declared variable num var byte[12] because it can take my number from num[0]="+" to num[12]="4"

I also declared sum var byte[21] because :
sum[0]="A" and so on upto sum[7]="="
and further
sum[8]="+"
sum[9]="4"
sum[10]="4"
sum[11]="7"
sum[12]="8"
sum[13]="3"
sum[14]="2"
sum[15]="2"
sum[16]="2"
sum[17]="5"
sum[18]="1"
sum[19]="4"
sum[20]="4"
sum[21]=13

and to fill sum[8] to sum[20] we need loop 13 times (sum[8] included), and so c=0 to 12

Also while serout it needs to transmit whole sum[0] to sum[21] so c=0 to 21.

Do you still feel this is the wrong way? Thanks

aratti
- 7th October 2009, 23:38
Include "MODEDEFS.BAS"
num var byte[13]
sum var byte[22]
c var byte

baud con 188

sum[0] = "A"
sum[1] = "T"
sum[2] = "+"
sum[3] = "C"
sum[4] = "M"
sum[5] = "G"
sum[6] = "S"
sum[7] = "="
sum[21]= 13

Serin2 rx,baud,5000,main,[WAIT("REC UNREAD"),SKIP 3, STR num\13, skip 28, STR sms\8]
checkms:
If sms[0]="d" and sms[1]="e" and sms[2]="a" and sms[3]="c" and sms[4]="t" then
For c=0 to 12
sum[c+8]=num[c]
next c
For c=0 to 21
serout tx,T2400,[sum[c]]
next c
Serin2 rx,baud,5000,checkms,[WAIT(">")]



The above (marked in red) are the correction needed.

Al.

financecatalyst
- 7th October 2009, 23:59
I have used a special routine so that to know if code is not getting stuck atleast after 5 tries which is as follows:

If sms[0]="d" and sms[1]="e" and sms[2]="a" and sms[3]="c" and sms[4]="t" then
i=i+1
if i=5 then
while 1
toggle portb.6
pause 100
wend : endif

for c=0 to 12
sum[c+8]=num[c]
next c
for c=0 to 21
serout tx,T2400,[sum[c]]
next c

Serin2 rx,baud,5000,checkms,[WAIT(">")]

Problem is that since I have made the last change of serin2....STR num\13, the code is getting stuck somewhere and not moving at all as it is not entering the toggle loop which it should after waiting 5 times for ">".

aratti
- 8th October 2009, 00:17
Sorry, I have forgotten to cange also the skip value after the string numeral:

Serin2 rx,baud,5000,main,[WAIT("REC UNREAD"),SKIP 3, STR num\13, skip 27, STR sms\8]

This should be one less since you have increased one byte the string.

Al.

financecatalyst
- 8th October 2009, 00:26
Yu huuuuuuu

thank you so much. It's working now