示例#1
0
def checkCon(pin):
    a = SER.send('DEBUG: Now in checkCon...\r\n')
    #print '\r\ncheckCon PIN:',pin
    res = MDM2.send('AT+CREG?\r',0)
    res = MDM2.receive(30)
    b = SER.send('DEBUG: following is result from AT+CREG?\r\n')
    c = SER.send(res);
    if ( (res.find('0,1') > -1)  or (res.find('0,5')  > -1 ) ):
        return 1

    ret = ''
    ret = setPin(pin)
    if ( ret != 1 ):
        GPIO.setIOdir(19,1,1)
        return -1 

    timer = MOD.secCounter() + 120
    while ( (res.find('0,1') == -1)  and  (res.find('0,5')  == -1 ) ):
        res = MDM2.send('AT+CREG?\r',0)
        res = MDM2.receive(20)
        b = SER.send('DEBUG: following is result from AT+CREG?\r\n')
        c = SER.send(res);
        if ( MOD.secCounter() > timer ):
            return -1
        MOD.sleep(50)
    MOD.sleep(20)
    return 1 
示例#2
0
 def sendAT(self, atcom, atres, trys = 1, timeout = 1, csd = 1):
     mdm_timeout = int(self.config.get('TIMEOUT_MDM'))
     s = MDM2.receive(mdm_timeout)
     result = -2
     while(1):
         if(csd):
             self.tryCSD()
         if(self.config.get('DEBUG_AT') == '1'):
             self.debug.send('AT OUT: ' + atcom)
         s = ''
         MDM2.send(atcom, mdm_timeout)
         timer = MOD.secCounter() + timeout
         while(1):
             s = s + MDM2.receive(mdm_timeout)
             if(s.find(atres) != -1):
                 result = 0
                 break
             if(s.find('ERROR') != -1):
                 result = -1
                 break
             if(MOD.secCounter() > timer):
                 break
         if(self.config.get('DEBUG_AT') == '1'):
             self.debug.send('AT IN: ' + s[2:])
         trys = trys - 1
         if((trys <= 0) or (result == 0)):
             break
         MOD.sleep(15)
     return (result, s)
示例#3
0
 def sendAT(self, atcom, atres, trys=1, timeout=1, csd=1):
     mdm_timeout = int(self.config.get('TIMEOUT_MDM'))
     s = MDM2.receive(mdm_timeout)
     result = -2
     while (1):
         if (csd):
             self.tryCSD()
         if (self.config.get('DEBUG_AT') == '1'):
             self.debug.send('AT OUT: ' + atcom)
         s = ''
         MDM2.send(atcom, mdm_timeout)
         timer = MOD.secCounter() + timeout
         while (1):
             s = s + MDM2.receive(mdm_timeout)
             if (s.find(atres) != -1):
                 result = 0
                 break
             if (s.find('ERROR') != -1):
                 result = -1
                 break
             if (MOD.secCounter() > timer):
                 break
         if (self.config.get('DEBUG_AT') == '1'):
             self.debug.send('AT IN: ' + s[2:])
         trys = trys - 1
         if ((trys <= 0) or (result == 0)):
             break
         MOD.sleep(15)
     return (result, s)
示例#4
0
def sendData(PIN,PO,HO,A,GU,GP,data,ll):
    b = SER.send('\r\nIn sendData...sending\r\n' + data + '\r\n')
    b = SER.send('\r\nHO=\r\n')
    b = SER.send(HO)
    b = SER.send('\r\npO=\r\n')
    b = SER.send(PO)
    b = SER.send('\r\n')
    a = openGPRS(PIN,A,GU,GP)
    a = openSD(HO)
    res = MDM2.send('POST /' + PO + ' HTTP/1.1 Connection: close\r\n', 0)
    res = MDM2.send('HOST: ' + HO + '\r\n', 0)
    res = MDM2.send('User-Agent: Terminal Connect\r\n', 0)
    res = MDM2.send('Content-Type: application/x-www-form-urlencoded\r\n', 0)
    res = MDM2.send('Content-Length: '+ str(ll) +'\r\n\r\n', 0)
    res = MDM2.send(data, 0)
    res = MDM2.send('\r\n\r\n', 0)
    cnt = 20
    res = MDM2.receive(20)
    a = SER.send('\r\nResponse from server ------------------------\r\n')
    while ( (res.find('EOT') == -1) and (cnt > 0) ):
        a = SER.send(res)
        res = MDM2.receive(20)
        cnt = cnt - 1
    a = SER.send(res)
    res = closeCon()
    a = SER.send('\r\nend -----------------------------------------\r\n')
    return res
示例#5
0
def setPin(pin):
    rr = ''
    tt = MOD.secCounter() + 30
    while ( rr.find('READY') == -1):
        rr = MDM2.send('AT+CPIN?\r',0)                   # CPIN Status
        rr = MDM2.receive(5)
        if ( rr.find('SIM PIN') != -1 ):
            bb = MDM2.send('AT+CPIN=' + pin + '\r',0)    # set PIN
            MOD.sleep(10)                                # wait 1sec
        if ( MOD.secCounter() > tt ):
            return -1 
        MOD.sleep(10)
    return 1
示例#6
0
def openSD(H):
    res = MDM2.send('AT#SD=1,0,80,' + H +',0\r', 0)
    timer = MOD.secCounter() + 30
    while (MOD.secCounter() < timer):
        res = MDM2.receive(10)
        a = SER.send('\r\nDEBUG: Back in openGPRS just did AT#SD=1,0,80....\r\n')
        a = SER.send(H)
        a = SER.send(res)
        if ((res.find('CONNECT') >= 0) ):
            timer = timer - 100
	    b = SER.send('\r\nsuccessfull connect, returning from openSD\r\n')
            return 1
        MOD.sleep(10)
    return -1
示例#7
0
 def tryCSD(self):
     ring = MDM2.getRI()
     if(ring == 1):
         at_timeout = int(self.config.get('TIMEOUT_AT'))
         a, s = self.sendAT('ATA\r', 'CONNECT', 1, 10, 0)
         if(a == 0):
             self.debug.send('CSD CONNECTED')
             while(ring == 1):
                 rcv = self.serial.receive(int(self.config.get('TCP_MAX_LENGTH')))
                 if(len(rcv) > 0):
                     self.sendMDM2(rcv)
                 rcv = self.receiveMDM2()
                 if(len(rcv) > 0):
                     self.serial.send(rcv)
                 ring = MDM2.getRI()
                 MOD.watchdogReset()
             self.debug.send('CSD DISCONNECTED')
         else:
             self.debug.send('CSD CONNECT ERROR')
示例#8
0
文件: gsm.py 项目: teleofis/Locker
def checkRing():
    data = MDM2.receive(5)
    pos = data.find('+CLIP')
    if(pos != -1):
        data = data[pos + 6:].strip()
        tokens = data.split(',')
        if(len(tokens) > 0):
            number = tokens[0].replace('"', '')
            return number
    return ''
示例#9
0
 def tryCSD(self):
     ring = MDM2.getRI()
     if (ring == 1):
         at_timeout = int(self.config.get('TIMEOUT_AT'))
         a, s = self.sendAT('ATA\r', 'CONNECT', 1, 10, 0)
         if (a == 0):
             self.debug.send('CSD CONNECTED')
             while (ring == 1):
                 rcv = self.serial.receive(
                     int(self.config.get('TCP_MAX_LENGTH')))
                 if (len(rcv) > 0):
                     self.sendMDM2(rcv)
                 rcv = self.receiveMDM2()
                 if (len(rcv) > 0):
                     self.serial.send(rcv)
                 ring = MDM2.getRI()
                 MOD.watchdogReset()
             self.debug.send('CSD DISCONNECTED')
         else:
             self.debug.send('CSD CONNECT ERROR')
示例#10
0
def closeCon():
    res = MDM2.send('+++\r', 10)
    timer = MOD.secCounter() + 30
    # Antwort +++ auswerten
    while (MOD.secCounter() < timer):
        res = MDM2.receive(10)
        if ((res.find('OK') >= 0) ):
            timer = timer - 100
        MOD.sleep(10)

    res = MDM2.send('AT#SH=1\r', 0)
    timer = MOD.secCounter() + 30
    # answere AT#SD
    while (MOD.secCounter() < timer):
        res = MDM2.receive(10)
        if ((res.find('OK') >= 0) ):
            timer = timer - 100
        MOD.sleep(10)
    # print '\r\ncloseCon =',res
    return res
示例#11
0
文件: gsm.py 项目: teleofis/Locker
def sendAT(request, response, timeout = 2, interface = 1):
    if(interface == 1):
        MDM.send(request + '\r', 2)
    else:
        MDM2.send(request + '\r', 2)
    result = -2
    data = ''
    timer = MOD.secCounter() + timeout
    while(MOD.secCounter() < timer):
        if(interface == 1):
            rcv = MDM.read()
        else:
            rcv = MDM2.read()
        if(len(rcv) > 0):
            data = data + rcv
            if(data.find(response) != -1):
                result = 0
                break
            if(data.find('ERROR') != -1):
                result = -1
                break
    return (result, data)
示例#12
0
文件: gsm.py 项目: teleofis/AntiTheft
def sendAT(request, response, timeout=2, interface=1):
    if (interface == 1):
        MDM.send(request + '\r', 2)
    else:
        MDM2.send(request + '\r', 2)
    result = -2
    data = ''
    timer = MOD.secCounter() + timeout
    while (MOD.secCounter() < timer):
        if (interface == 1):
            rcv = MDM.read()
        else:
            rcv = MDM2.read()
        if (len(rcv) > 0):
            data = data + rcv
            if (data.find(response) != -1):
                result = 0
                break
            if (data.find('ERROR') != -1):
                result = -1
                break
    return (result, data)
示例#13
0
 def receiveMDM2(self):
     data = ''
     size = int(self.config.get('TCP_MAX_LENGTH'))
     while(1):
         rcv = MDM2.read()
         if(len(rcv) > 0):
             self.buffer = self.buffer + rcv
             if(len(self.buffer) > size):
                 break
         else:
             break
     if(len(self.buffer) > 0):
         data = self.getBuffer(size)
         if(data.find('NO CARRIER') != -1):
             raise Exception, '"NO CARRIER" on CSD connection'
         self.debug.send('Data received from CSD connection: ' + str(len(data)) + ' bytes')
     return data
示例#14
0
 def receiveMDM2(self):
     data = ''
     size = int(self.config.get('TCP_MAX_LENGTH'))
     while(1):
         rcv = MDM2.read()
         if(len(rcv) > 0):
             self.buffer = self.buffer + rcv
             if(len(self.buffer) > size):
                 break
         else:
             break
     if(len(self.buffer) > 0):
         data = self.getBuffer(size)
         if(data.find('NO CARRIER') != -1):
             raise Exception, '"NO CARRIER" on CSD connection'
         self.debug.send('Data received from CSD connection: ' + str(len(data)) + ' bytes')
     return data
示例#15
0
 def sendATMdm2(self, atcom):
     mdm_timeout = int(self.config.get('TIMEOUT_MDM'))
     MDM2.send(atcom, mdm_timeout)
     self.debug.send('DATA AT OUT: ' + atcom)
示例#16
0
 def sendMdm2(self, data):
     MDM2.send(data, 50)
     self.debug.send('Sending data MDM2: ' + str(len(data)) + ' bytes')
示例#17
0
def openGPRS(P,A,GU,GP): #PIN = CONFIG.config['PIN_SIM'],H = CONFIG.config['HOST'],A = CONFIG.config['APN']
    a = SER.send('\r\nDEBUG: Now in openGPRS.\r\n')
    ret = checkCon(P)
    a = SER.send('\r\nDEBUG: Back in openGPRS after doing checkCon.\r\n')
    if ( ret != 1 ):
        return -1
    a = SER.send('\r\nDEBUG: Back in openGPRS about to do AT#SGACT?.\r\n')
    res = MDM2.send('AT#SGACT?\r', 2)
    timer = MOD.secCounter() + 20
    while (MOD.secCounter() < timer):
        res = MDM2.receive(10)
        a = SER.send('DEBUG: Back in openGPRS just did AT#SGACT?.\r\n')
        a = SER.send(res)
        if ((res.find(',0') >= 0) ):
            timer = timer - 100
        if ((res.find(',1') >= 0) ):
            timer = timer - 100
            #print 'GPRS stil active\r'
            return 1
        MOD.sleep(10)

    res = MDM2.send('AT+CGDCONT=1,"IP","' + A + '","0.0.0.0",1,1\r', 0)
    timer = MOD.secCounter() + 30
    # check answer CGDCONT
    while (MOD.secCounter() < timer):
        res = MDM2.receive(10)
        a = SER.send('\r\nDEBUG: Back in openGPRS just did AT#CGDCONT?.\r\n')
        a = SER.send(res)
        if ((res.find('OK') >= 0) ):
            timer = timer - 100
        MOD.sleep(10)

    if (GU != ''):
        print 'set GPRS username\r'
        res = MDM2.send('AT#USERID="'+ GU + '"\r', 2)
        res = MDM2.receive(20)
        res = res.find ('OK')
        if (res == -1):
            a = SER.send('\r\nerror setting GPRS username\r\n')    

    if (GP != ''):
        print 'set GPRS password\r'
        res = MDM2.send('AT#PASSW="'+ GP + '"\r', 2)
        res = MDM2.receive(20)
        res = res.find ('OK')
        if (res == -1):
            a = SER.send('\r\nerror setting GPRS password\r\n') 


    res = MDM2.send('AT#SGACT=1,1\r', 1)
    timer = MOD.secCounter() + 50

    while (MOD.secCounter() < timer):
        res = MDM2.receive(10)
        a = SER.send('\r\nDEBUG: Back in openGPRS just did AT#SGACT=1.\r\n')
        a = SER.send(res)
        if (res.find('#SGACT:') >= 0):
            timer = timer - 100
            res = cleanCRLF(res)
            res = res.replace('#SGACT:','')
            res = res.replace('OK','')
            a = SER.send('\r\nConnected with IP:' + str(res))
            return 1
        MOD.sleep(10)
    return -1
示例#18
0
 def sendMDM2(self, data):
     MDM2.send(data, 50)
     self.debug.send('Sending data to CSD: ' + str(len(data)) + ' bytes')