ASCII control codes advcie please

BrendanP

Senior Member
Im trying to send a sms containing byte values within the message. Im having difficulty understanding how to use the control codes to put the message together ina way the compiler can accept and also that module will understand.

The line of code below will work fine. The byte values b0 to b9 hold the number the sms is to go to. I enclose these byte values within the two 34,34's rather than " and " because that seems to be the only way the thing will go through. I havent bothered mroe with it than that bacause it works fine and Ive got enough to stress over as it is.


hserout 0,("AT+CMGS=",34,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,34,13,"DIPPY IS FULL OF WORDS OF LOVE",26)


The line of code below doesn't work.

hserout 0,("AT+CMGS=",34,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,34,13"THE BATTERY LEVEL IS,40,b10,41,40,b11,41",26)


As before the destination number is held in the bytes b0 to b9. I then want to send a two numeral number which reprsents the battery level's state of charge as a precentile which is contained with bytes b10 and b11. I thought maybe they should be enclosed in brackets.

In practice I also want to add a % sign after the two byte values but I have left that out for clarity.

The messge should read at the recieving end "The battery charge level is 40%"


At the moment the compiler will accpet this command but the module dosent send it.


The 26 (ctrl z) tells the module thats the end of the message and to switch from taking in text mode back to at command mode.

So the issue is I think how do I put the message together so the compiler understands b10 and b11 per se arent part of the message but rather contain values that are. Im sure its straight forward to the more experience players. Any advice appreciated. (espscially from that old honey dripper Dippy).

hserout 0,("AT+CMGS=",34,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,34,13"THE BATTERY LEVEL IS,40,b10,41,40,b11,41",26)
 

Technical

Technical Support
Staff member
hserout 0,("AT+CMGS=",34,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,34,13,"THE BATTERY LEVEL IS ",b10,b11,"%",26)

this assumes b10 and b11 are already ascii characters

it may be easier just to use b10 as a real number (can be 0-255) then the code is

hserout 0,("AT+CMGS=",34,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,34,13,"THE BATTERY LEVEL IS ",#b10,"%",26)
 
Last edited:

BrendanP

Senior Member
The message goes through now to the destination with your fix Tech but I have a further problem

Im getting from the scratch pad two numerals from two ptr positions that I had been loading into the two bytes b10 and b11.

If I try and send through both #b10 and #b11 the message wont go through.

A single #b10 does go through.

So the question now is how do I combine the two seperate (ie, 6 and 0 which means the battery is at 60%) numerals from the pad into a single numeral I can end out in a single #byte? (i.e. 60)


Hmmmm, because I have a limited range of possible numbers I can just have a if b10 = X and b11 = Y then b12=I and the send #b12.

That will work, let me know if theres a more elegant way to do it Tech. Thanks.

Is this done with some clever math formula?
 
Last edited:

BCJKiwi

Senior Member
Don't quite understand where the issue is.

if b10 contains 6
and b11 contains 1
then
b10*10 gives 60
+b11 gives 61
so b12 = b10 * 10 + b11 gives 61.

so the program snippet becomes;
Code:
b12 = b10 * 10 + b11
hserout 0,("AT+CMGS=",34,b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,34, 13,"THE BATTERY LEVEL IS ",#b12,"%",26)
used this construct many times.
 

hippy

Ex-Staff (retired)
@ BrendanP : That should work. Try connecting the serial output to the Programming Editor Terminal or a Terminal Emulator and check to see exactly what it is putting out. You'll be better off with a Terminal Emulator which can show the hex values of the bytes which don't normally display ( single CR's and Ctrl-Z etc ). That might require running the serial through an inverter to the PC.

You could also try setting up background receive to see what the phone replies with.

Have you tried replacing #b12 with a hard-wired "61" or #61 ? It may have something to do with message length or something else weird. If that works I don't see any reason why #b12 shouldn't - Put "b12=61" immediately before to ensure you know what is in b12 at that point in time and try again.
 

BrendanP

Senior Member
Thanks guys.

I do use the terminal to keep track of what is happening as the program runs through. The module provides feed back which I catch on the scratch pad and sertxd.

I issue the AT com and read through the scratch pad looking for the correct reply sequence. The problem seems to be converting /moving the data from the ptr to the byte. It seems that something happens to it during that transition and it becommes corrupted.

Im not too stressed as I know I'll sort it out. I'll go ahead and finish the rest of the program and come back to that. I've got the rest of the tricky parts of the program and hardware issues sorted.


Im going to be away for a few days. Im nearly broke, I haven't worked in 8 weeks, got plenty done on this thing though in that time.

I'm going up to work at a near by ski resort over the winter. Ill keep hacking up there on the note book and be back home on the weekend and will check in and let you know what is happening. I may be able to get on line up there perhaps.

I greatly appreciate the support I get on this forum.
 
Top