Exemple #1
0
#a = MDM.receive(15)
#SER.send('AT+CLIP=1 - ' + a +'\r\n')
timeout = MOD.secCounter() + TIMEOUT_VALUE

while MOD.secCounter() < timeout:


    #res = SER.read()
    #while (len(res) == 0) and (MOD.secCounter() < timeout):
    #    res = res + SER.read()
    #if res.find('RING') != -1:
    #    print 'I have a call'

    #counter = counter + 1
    #SER.send('Try ' + str(counter) + '\r\n')
    if MDM.getRI() == 1:
        #SER.send('I have a ring\r\n')
        MDM.send('AT+CLCC\r',1)
        md = MDM.receive(10)
        if md.find('9118468668') != -1:
            SER.send('I have a call from you!\r\n')
            MOD.sleep(30)
            MDM.send('ATH\r',0)
        #SER.send('mds = ' + str(mds) + '\r\nmd = ' + str(md) + '\r\n')


SER.send('+++ END +++\r\n')

#RING
#
#+CLIP: "+79118468668",145,"",128,"",0
    initAT()
    initGPIO()
    print 'GPIO init OK, AT init OK'
    
    print 'Switch to SIM1'
    ACTIVE_SIM = 1
    disableSIM()
    turnOnSim1()
    enableSIM()

    timer = MOD.secCounter() + NETWORK_WAIT_TIME
    
    while(1):
        resetWatchdog()
        
        ring = MDM.getRI()
        if(ring == 1):
            print 'Incoming connection, sleep'
            timer = MOD.secCounter() + NETWORK_WAIT_TIME
            MOD.sleep(MAIN_LOOP_PERIOD * 10)
            continue

        print 'Active SIM: %d Timer: %d' % (ACTIVE_SIM, timer - MOD.secCounter())
        
        creg = checkCREG()
        if(creg == 0):
            csq = checkCSQ()
            print 'REGISTERED CSQ: %d' % (csq)
            if(csq > 10):
                print "CSQ > 10, updating timer"
                timer = MOD.secCounter() + NETWORK_WAIT_TIME