Read SMS from Mobile Phone

polyarts

New Member
Hello @ All,
i'm trying since a few days to figure out how to converte the serial recived Charcaters from my Mobile Phone S35 back to an ASCII string.
I Work with the 28x1 Picaxe.
The Mobile Phones TXD is connected to the HSERIN Pin, RXD to Pin0 (AT commando is send via SEROUT 0, N19200_16 ..etc)
Converting bin to PDU and Sending SMS Works already fine.

When i read back an SMS i dont get the Ascii Characters like in Windows Hyper Terminal to the PicAxe.

*********************
The right data recived from the Mobile Phone in Hyper Terminal looks like this:
- +CMGL: 12,2,,16
- 0791947106004034110000810000FF0931D98C0642C67A30
-
- OK
(62 ascii characters)

*********************
The same data at the PicAxe recived from the Mobile Phone (character Nr. 0 to 62):
Code:
NR.0 = 95         
NR.1 = 85         
NR.2 = 45         
NR.3 = 149          
NR.4 = 197          
NR.5 = 157          
NR.6 = 21         
NR.7 = 155          
NR.8 = 0        
NR.9 = 121          
NR.10 = 121           
NR.11 = 189           
NR.12 = 45          
NR.13 = 149           
NR.14 = 197           
NR.15 = 112           
NR.16 = 45          
NR.17 = 191           
NR.18 = 157           
NR.19 = 155           
NR.20 = 167           
NR.21 = 155           
NR.22 = 167           
NR.23 = 167           
NR.24 = 157           
NR.25 = 147           
NR.26 = 229           
NR.27 = 235           
NR.28 = 0         
NR.29 = 22          
NR.30 = 6         
NR.31 = 99          
NR.32 = 103           
NR.33 = 99          
NR.34 = 89          
NR.35 = 214           
NR.36 = 246           
NR.37 = 54          
NR.38 = 246           
NR.39 = 246           
NR.40 = 118           
NR.41 = 246           
NR.42 = 150           
NR.43 = 118           
NR.44 = 6         
NR.45 = 103           
NR.46 = 103           
NR.47 = 246           
NR.48 = 246           
NR.49 = 246           
NR.50 = 246           
NR.51 = 157           
NR.52 = 159           
NR.53 = 159           
NR.54 = 159           
NR.55 = 159           
NR.56 = 115           
NR.57 = 115           
NR.58 = 159           
NR.59 = 141           
NR.60 = 153           
NR.61 = 157           
NR.62 = 119
*********************
The Programm to Send this log:
Code:
hsersetup b19200_16, %00
setfreq em16

main:
if pin5 = 1 then send
goto main

send:
low portc 3 'led

serout 0,n19200_16, ("AT+CMGL=2",13,10)   'send SMS read command

hserin 0,62                                             'put 63 chars in scratchpad
hsersetup off

for b0 = 0 to 62
get b0,b1
sertxd ("NR.",#b0," = ",#b1,13,10)              'log to terminal
next b0

high portc 3 'led

goto main
*********************
Does anyone knows how to convert the Picaxe recieved data Nr. 0 - 62
back to ASCII Characters?

Like Nr.61( dezi 157) will be $33 (ascii "3")
and Nr.62( dezi 119) $30 (ascii "0")

Greets
Dom
 
Last edited:

Technical

Technical Support
Staff member
simply remove the # from #b1 in the receive program. The raw data (ie ascii) will then be displayed in your sertxd lines.
 

hippy

Technical Support
Staff member
simply remove the # from #b1 in the receive program. The raw data (ie ascii) will then be displayed in your sertxd lines.
Well it would be if the data actually represented the characters !

Unfortunately the text received is mainly 'garbage', not sensible ASCII at all. What the problem is I have no idea - Could it be a signal polarity or timing or synchronisation issue ( put HSERIN before SEROUT ) ?
 

polyarts

New Member
I think its like hippy says, manly garbage.
When i send the data without the "#" it still makes nonsense.

These settings works fine at the Hyper Terminal:
Baudrate 19200, Databits 8, No Parity, 1 stop Bit
Sending as well as Receaving the Data.

->put HSERIN before SEROUT

To make the Mobile Phone send the content of the selected SMS,
i have to send the AT commando first.

Could it be an error, why using different Serial input types (serin, sertxd, hserin)?
 

hippy

Technical Support
Staff member
HSERIN is separate to SEROUT so it should work when put before SEROUT. What it ensures is that the PICAXE is ready and waiting as the AT command is sent. After the SEROUT there's a delay before HSERIN gets configured and during that time you may be missing data or losing synchronisation. I'll admit I've not tried any of this so it's all theory.

If HSERIN 0,62 waits until it's received 62 characters then that's a problem; it won't receive until you've told it to with the SEROUT. In that case you may have to operate HSERIN in background receive mode.
 

polyarts

New Member
I changed the programm to use only the hserin/hserout commands.
But still seems like garbage.
Code:
hsersetup b19200_16, %10
setfreq em16
main:
if pin5 = 1 then send
goto main

send:
low portc 3 'led

hserout 0, ("AT+CMGL=2",13,10) 'send SMS read command

hserin 0,63 'put 63 chars in scratchpad


for b0 = 0 to 63
get b0,b1
hserout 0, ("NR.",#b0," = ",#b1,13,10) 'log to terminal
next b0

high portc 3 'led

goto main
I was loging the data 4 times and it looks like this:

Code:
NR.0 	95	95	95	71
NR.1 	85	85	85	85
NR.2 	45	45	45	45
NR.3 	149	42	42	     
NR.4 	197	197	197	197
NR.5 	157	157	157	58
NR.6 	21	21	21	21
NR.7 	155	155	155	155
NR.8 	229	229	229	229
NR.9 	0	0	0	0
NR.10 	121	121	121	121
NR.11 	189	189	189	189
NR.12 	45	45	45	45
NR.13 	149	42	42	149
NR.14 	197	197	197	197
NR.15 	16	96	96	80
NR.16 	45	45	45	45
NR.17 	191	191	191	191
NR.18 	157	157	157	157
NR.19 	155	155	155	155
NR.20 	167	163	163	167
NR.21 	155	155	155	155
NR.22 	167	167	167	167
NR.23 	167	167	167	163
NR.24 	157	157	157	157
NR.25 	147	147	147	147
NR.26 	229	229	229	11
NR.27 	235	235	235	61
NR.28 	0	0	0	22
NR.29 	22	22	22	6
NR.30 	6	6	6	99
NR.31 	99	99	99	13
NR.32 	13	13	13	99
NR.33 	99	99	99	89
NR.34 	89	89	89	214
NR.35 	214	214	214	246
NR.36 	246	246	246	54
NR.37 	54	54	54	246
NR.38 	246	246	246	246
NR.39 	246	246	246	118
NR.40 	118	54	54	246
NR.41 	246	246	246	150
NR.42 	150	150	150	118
NR.43 	118	54	54	6
NR.44 	6	6	6	13
NR.45 	13	13	13	13
NR.46 	13	13	13	246
NR.47 	246	246	246	246
NR.48 	246	246	246	246
NR.49 	246	118	118	246
NR.50 	246	143	143	157
NR.51 	157	157	157	159
NR.52 	159	159	159	131
NR.53 	159	159	159	159
NR.54 	159	159	159	159
NR.55 	159	159	159	115
NR.56 	115	115	115	115
NR.57 	115	115	115	159
NR.58 	135	159	159	141
NR.59 	141	141	141	153
NR.60 	153	153	153	157
NR.61 	157	157	157	119
NR.62 	119	119	119	141
NR.63 	0	0	0	0
The data seems to be a little bit different every time.

How else can i receive Serial Data to the PicAxe background ? ..without doing this in a loop like
Code:
for b0 = 0 to 62
serin 0, n19200_16, (b1)
put b0,b1
next b0
and whats the different between receiving the data in hyper terminal or at the PicAxe?
Do i have to remove the stop bits? or invert, mirror the bits of every character?
 

hippy

Technical Support
Staff member
I changed the programm to use only the hserin/hserout commands. But still seems like garbage.

Yes, that's what I'd expect if this were a receive timing issue. The slight differences in data would be down to at exactly what point in time the phone starts sending data back. The phone likely doesn't always respond immediately it gets a command so the PICAXE program will likely have progressed slightly further than other times when data is received back.

Once the HSERIN synchronises correctly with the data it should stay in synch. If it doesn't that will need to be addressed but the first thing is getting it in synch to start with.

How else can i receive Serial Data to the PicAxe background ?

I've not done it myself but you'll need to use the HSERSETUP command to enable background receive. That's described in Manual 2 and a Forum Search should find other discussions and example of background receive.

whats the different between receiving the data in hyper terminal or at the PicAxe?

The main difference is that PC buffers everything received so nothing gets lost while the PC is busy doing something else and it also captures incoming data while you are sending data. The PC then delivers what's received a byte at a time to the application with that being handled within the PC itself. HyperTerm itself will also drop characters which it doesn't understand so what you see is not necessarily exactly what was sent.

For the PICAXE you have to use HSERIN set for background receive to achieve the same with receive buffering, and extracting received bytes has to be done under your own program control.

Do i have to remove the stop bits? or invert, mirror the bits of every character?

You shouldn't have to. Providing they're correctly configured and synchonised, both SERIN and HSERIN should read the incoming serial data correctly.

The most important thing is that SERIN or HSERIN are ready to receive data before it starts arriving. If it starts late it may miss part of what's been sent and then misinterpret the rest of the data stream. That looks like what is happening to me.

There may be some benefit in sending a simpler command ( AT or something to get an OK back, or an ATIx to get a fixed string back ) to get HSERIN working first. There may also be some benefit in terminating the AT commands with just CR or LF rather than both to see if that helps.
 

hippy

Technical Support
Staff member
One test you can do is to wire the phone so it recives commands from the PC using Hyperterm and then take the phone's output to the PC and to the PICAXE. Write some code on the PICAXE which will read what's expected back then send it to another PC, or with a slightly more complicated arrangement also to Hyperterm.

Which leads me to ask ...

How exactly are you connecting the phone to the PC, and how exactly are you connecting the phone to the PICAXE ?

Asuuming you have a phone-to-serial lead you plug into the PC which works with HyperTerm, and you're using the same cable with the PICAXE, you'll need inverters or a MAX232 or similar between the cable and the PICAXE.

You say sending SMS works fine but is that with SEROUT N19200_16 ? If so the output doesn't need inverting but the input for HSERIN does.
 

polyarts

New Member
The Phone is connected with the original Siemens RS232 cabel.
I use a D-Sub connector and plug it to my Breed board.
pin5 -> gnd
pin2 -> RXD
pin3 -> TXD
Polarity is same like to the pc.
With the picaxe serial download cable i log the data back to the PC.

->@ SEROUT N19200_16
Yes, these settings are working when sending SMS.

->@ If so the output doesn't need inverting but the input for HSERIN does
Inverting works only with the HSEROUT command, right?

Gotta try to get a Qualifier by using Serin T19200_16 and
log the data like u describet in your last post.
 

hippy

Technical Support
Staff member
A SEROUT N19200_16 followed by a SERIN N19200_16 would be a wothwhile test and should work without any inversion ( that is, connect PICAXE straight to the D-connector ).

It might not catch all the data but it should hopefully give enough to show you're on the right track ...

Code:
serout 0,n19200_16, ("AT+CMGL=2",13,10) ' To phone
do
  serin ?,n19200_16,b0                  ' From phone
  sertxd (b0)                           ' To HyperTerm
loop
 

tiscando

Senior Member
recieve timing issue:-
i have translated some of this data in to binary, compared it, and it just seems to have gone corrupt.

windows hyper terminal: 00101011,01000011,01001101,01000111,01101100,00111010
ascii + C M G L :
decimal 43, 67, 77, 71, 76, 58,
hex $2b $43 $4d $47 $4c $3a

picaxe 28x1 (h)serin : 01011111,01010101,00101101,10010101,11000101,10011101
decimal 95 85 45 149 197 157
hex $5f $55 $2d $95 $c5 $9d

try setting the hsersetup command so it automatically recieves signals in the background, e.g.

hsersetup b19200_16, %11
...
send:
low portc 3
hserout ...
do
loop until hserflag=1
pause 100
for...
...

Only if you are able to 'hard-reset' your picaxe in any way (via a reset button) , try having the 'calibfreq' command before the 'hsersetup' command and experiment with different values (firstly negative values between -4 and -1) until you get the right data.
 
Last edited:

Technical

Technical Support
Staff member
hsersetup b19200_16, %10

You are inverting the hserout signal (%10), presumably to get the phone to respond. This proves you need inverted polarity (and that the baudrate timing is actually ok, otherwise the phone wouldn't respond to the hserout command to start with!).

But as it is not possible to invert hserin, so it looks like your data is corrupt because it is inverse of what it should be and so will be totally mixed up. Therefore you need a hardware inverter (NOT gate) before the hserin pin to use this hardware serial method.

Otherwise you can only use serin/serout with 'n' baud rates.
 
Last edited:

polyarts

New Member
@ hippy,
I was trying it out your way, 4 times
the result is here:

12911329615073112121266113130981012912299131310
129113125136150731121212661131309810129122115131310
12915729615073112121266113130114669817999131310
129255140136150731121212661131301146611416399131310

the data is send as "sertxd (#b0 )"
seems like some data is lost like u say, but its still not the right character recived.
(also without the "#")

@tiscando,
do u mean
Code:
hserout ...
do
loop until ->"hserinflag=1"<-
pause 100
high portc3
for...
to calib the freq from -4 to +4 brings no change to the data.
Does the "calibfreq" eaven make a change when i use the hsersetup b_19200?
In the manual is written it calibrates the internal resonator.
..all so the programm never passes the do loop (no lighting led after the loop).

@technical
Will the data i recived be different when i use a inverter?
The "serin N19200_16" command shows up some results like at the head of this Thread.
Or is just some data missing becourse the PicAxe can't catch the data fast enough this way?
 

polyarts

New Member
Yes,it works

here is the code

Code:
hsersetup b19200_16, %10
setfreq em16
main:
if pin5 = 1 then send
goto main

send:
low portc 3 'led

serout 0,n19200_16, ("AT+CMGL=2",13,10) 'send SMS read command

hserin 0,63 'put 63 chars in scratchpad
hsersetup off

for b0 = 0 to 63
get b0,b1

sertxd ("NR.",#b0," = ",b1,13,10) 'log to terminal
next b0

high portc 3 'led

goto main
In the case someone looking for the solution:

The serout signal from PicAxe pin0 -> to the Phones serial cable to pin3
Pin2 of the Serial cabel is connected to pin11 of an max2323 inverter
The Hserin signal comes from the inverter max2323 pin14
Pin5 of the Serial Phone cable to GND.

Thank You People!! for Helping me geting trough this!!
Thanks!! Youre Great!!
 
Top