hserin and sms controller


Closed Thread
Results 1 to 26 of 26

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    48


    Did you find this post helpful? Yes | No

    Default rest of code

    Code:
    '---------------------------------------------------------------------
    ' provjeri sms inbox
    '---------------------------------------------------------------------
    main:
    
    p:
    HSerout ["ATZ",13,10]                   ' pocni komunikaciju,resetuj modem!
    HSERIN 4000,p,[WAIT("OK")]
    tm:
    HSerout ["AT+CMGF=1",13,10]             'postavi text mod
    HSERIN 2000,tm,[WAIT("OK")]
    
    m:
    HSEROUT["AT+CPMS=",34,"SM",34,13,10]    'ciljana memory lokacija
    HSERIN 2000,m,[WAIT("OK")]
    ws:
    gosub sc1                               'odi provjeri temperaturu
    
    HSEROUT["AT+CMGL",13,10]                'filter za query
        LCDOUT $FE,1,"cekaj sms!"
    
    HSERIN 5000,ws,[WAIT("REC UNREAD"),skip 3,str telbr\12,skip 12,str TIME\6,skip 8,STR PORUKA\3\13]'trazi unread
    lcdout $FE,1,telbr[6],telbr[7],telbr[8],telbr[9],telbr[10],telbr[11]
    pause 3000
    
    tbr[6]="8"
    tbr[7]="3"
    tbr[8]="1"
    tbr[9]="0"
    tbr[10]="x"'your phone number last two digits, oli zadnje dvije cifre vaseg broja
    tbr[11]="y"
    
    broj=1
    for x=6 to 11
       if TELBR[x]<>tbr[x] then broj=0
    next x
    lcdout $FE,$c0,tbr[6],tbr[7],tbr[8],tbr[9],tbr[10],tbr[11]
    pause 2000
    
    IF broj=0 then gosub s4
    
    
    grijanje[1]="U"                                 'turn on heating 
    grijanje[2]="G"
    
    istaporuka2=1
    FOR K=0 to 1  
        if poruka[K+1]<>grijanje[K+1] then istaporuka2=0
    next K
    
    if istaporuka2=1 then gosub s1                     'ako se sve poklapa idi na slanje poruka
                                                        'ukljucene poreosaca
    
    grijanj[1]="I"                                  'turn off heating
    grijanj[2]="G"
    
    
    IstaPoruka1=1
    FOR L=0 to 1  
        if poruka[L+1]<>grijanj[L+1] then IstaPoruka1=0 'ako se slova iz naredbe ne poklapaju
    next L                                               'istaporuk1=0
    
    if IstaPoruka1=1 then gosub s2                      'ako se sve poklapa idi na slanje poruka
                                                        'iskljucenje poreosaca
                                                        
                                                        
    
    tmp[1]="T"                            'ask for temperature in object
    tmp[2]="P"
    
    
    IstaPoruka3=1
    FOR J=0 to 1  
        if poruka[J+1]<>tmp[J+1] then IstaPoruka3=0 'ako se slova iz naredbe ne poklapaju
    next j                                              'istaporuk1=0
    
    if IstaPoruka3=1 then gosub s3                      'ako se sve poklapa idi na slanje poruka
                                                        'temperatura u objektu
    
    ' ------------------------------------------------------------
    ' brisanje poruke iz memeorije
    ' ------------------------------------------------------------
    mm:
    HSEROUT["AT+CPMS=",34,"SM",34,13,10]    'ciljana memory lokacija
    HSERIN 2000,mm,[WAIT("OK")]
    
    d:
    HSEROUT["AT+CMGD=1",13,10]              'brisi poruku iz mem loc SM sa indexom 1
    HSERIN 2000,d,[WAIT("OK")]
            LCDOUT $FE,1,"sms izbrisan!"
            pause 1500
    GOTO ws
    
    
    
    
    'subrutines
    '---------------------------------------------------------------
    
    '
    'subrutine za on/off-i potrosca i obavjest korisnika o poduzetoj akciji
    'i provjeru pristigle poruke
    '---------------------------------------------------------------
    s2:
    
      if IstaPoruka1=1 then low portd.0
        LCDOUT $FE,1,"isklj grijanje!"
        HSerout ["AT",13,10]
           Pause 1000
        HSerout ["AT+CMGF=1",13,10] 'Postavi Text Mode
           Pause 1000    
        HSerout ["AT+CMGS=",34,"+387618310xx",34,",129",13,10]  
          pause 500    
        HSerout [str poruka\3,str time\6,10,13]
        s21:
            HSerout [26]
            hserin 6000,s21,[WAIT("OK")]
      return
    
    s1:
    
        if istaporuka2=1 then high portd.0
            LCDOUT $FE,1,"uklj grijanje!"
            HSerout ["AT",13,10]
                Pause 1000
            HSerout ["AT+CMGF=1",13,10] 'Postavi Text Mode
                Pause 1000    
            HSerout ["AT+CMGS=",34,"+387618310xx",34,",129",13,10]
                pause 500
            HSerout [str poruka\3,str time\6,13,10]
                s11:
                HSerout [26]
                hserin 6000,s11,[WAIT("OK")]
        return
    
    
    '--------------------------------------------------------------
    'temperatura sa ds1820
    '--------------------------------------------------------------
    
    sc1:
    
       OWOut ow, 1, [$CC, $44]       ' pocni temp konverziju
    
    wc: 
       OWIn ow, 4, [cr]	' provjeri da'l se jos konvertuje
       If cr = 0 Then wc
       OWOut ow, 1, [$CC, $BE]		' ocitaj temp
       OWIn ow, 0, [temp.LOWBYTE, temp.HIGHBYTE, Skip 4, cr, cpc]
       ' izracunaj temp u C na 2 decimale
      temp = (((temp >> 1) * 100) - 25) + (((cpc - cr) * 100) / cpc)
       
       Lcdout $fe, 1,"Trenutna temp:"' prikazi temp
       lcdout $FE,$c0,128,DEC (temp / 100), ".", DEC2 temp, " C"'"izaberite temp "
       
                if temp >= posttemp then gosub s3    ' ako je uslov ispunjen salji upozorenje 
             
       pause 2000
     ' goto sc1
      return 
    '-----------------------------------------------------------------
    'prekoracenje temperature salji sms s3 pozorenja i pogresan korisnik s4
    '-----------------------------------------------------------------
    
    s3:
            LCDOUT $FE,1, "Salji temp!"
            HSerout ["AT",13,10]
                Pause 1000
            HSerout ["AT+CMGF=1",13,10] 'Postavi Text Mode
                Pause 1000    
            HSerout ["AT+CMGS=",34,"+387618310xx",34,",129",13,10]
                pause 500
            HSerout ["Temp:",dec (temp/100),10,13]
    
            s31:
                HSerout [26]
                hserin 6000,s31,[WAIT("OK")]
        return
    
    
    s4:
                LCDOUT $FE,1,"nemate prava!"
            HSerout ["AT",13,10]
                Pause 1000
            HSerout ["AT+CMGF=1",13,10] 'Postavi Text Mode
                Pause 1000    
            HSerout ["AT+CMGS=",34,str telbr\12,34,",129",13,10]
                pause 500
            HSerout ["nemate prava",str time\6,13,10]
                s12:
                HSerout [26]
                hserin 6000,s12,[WAIT("OK")]
        goto mm     
    End

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,144


    Did you find this post helpful? Yes | No

    Default

    Do you have any problem with this program, or ist an example?

    I have say to that is long enough! I have a little difficulty followng the s1, s12 named subs. Better use names to understand after a month what this sub do.

    Ioannis

  3. #3
    Join Date
    Mar 2009
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ioannis View Post
    Do you have any problem with this program, or ist an example?

    I have say to that is long enough! I have a little difficulty followng the s1, s12 named subs. Better use names to understand after a month what this sub do.

    Ioannis
    its a example, but everything is working just fine, thos subs s1 to s4 is mesages for users!!!turn on heating, turn off heating, temperature in object and u dont have autorizathion for device!!! and once again thx for help!!!

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,144


    Did you find this post helpful? Yes | No

    Default

    You are welcome. Thanks for posting your work too.

    Ioannis

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,144


    Did you find this post helpful? Yes | No

    Default

    After a lot of experimenting with the SMS subject, I noticed all by chance, that when my provider sent an SMS for advertisment purposes, the program could not handle it properly because in Hserin line to get the SMS, a 10 digit number was expected and not the 4 digit one.

    Keep in mind that the "defaults" may not always be default enough!

    Here is my test subroutine:
    Code:
    read_sms:
    	Lcdout com,line1,"Reading SMS"
    	HSerout ["AT+CMGL=",34,"ALL",34,13]  '"ALL" is for Wavecom module. Read all SMS 
    	' Read Caller ID etc. The timeout value in the HSERIN statement is important.
    	' it takes some time before the phone replies to the AT+CMGL command
    	HSerin 5000,ex_sms4,[wait("READ"),wait("+30"),str cc_phone\10,wait(44,44,34),SKIP 23,STR array\15\13] 'Number is waitstr command\10
    	LCDOut com,1,"Read 1 SMS"
    	pause 1000
    sms_delete:
    	LCDOut com,1,"Deleting SMS"
    	HSerout ["AT+CMGD=1,4",13]			'Delete all messages
    	HSerin 19000,ex_sms2,[wait("OK")]     'Wait for OK (null)
    	LCDOut com,line1,"Deleted SMS "
    	Pause 1000
    	return
    ex_sms2:    'No new message or timeout error
    	LCDOut com,line2,"Error",rep " "\11:Pause 1000
    	return
    ex_sms4:    'Wrong Number!
    	LCDOut com,line2,"Error phone Nbr":Pause 1000
    	goto sms_delete
    At the 3rd command line where HSerin 5000,ex_sms4,[wait... is executed, the command waits for +30 which is the country code for Greece, then I get 10 digits for the phone that is sending the SMS.

    But if the sender has only 4 digits I now through the timeout, jump to ex_sms4 and after an LCD message, the new and irrelevant SMS is deleted.


    Hope this helps all that deal with SMS stuff.

    Ioannis

Similar Threads

  1. Replies: 11
    Last Post: - 19th August 2009, 15:23
  2. problem with the GSM controller
    By Dariolo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th May 2009, 20:33
  3. Replies: 0
    Last Post: - 21st May 2009, 00:58
  4. parsing string from hserin
    By xxxxxx in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 2nd April 2009, 18:42
  5. Reading a SMS to an array
    By KA5MAL in forum GSM
    Replies: 3
    Last Post: - 17th June 2008, 17:24

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts