コード例 #1
0
ファイル: gsm.py プロジェクト: suhvm/wrx100_telit_gprs_python
 def sendATData(self, atcom, atres, trys=1, timeout=1, csd=1):
     mdm_timeout = int(self.config.get('TIMEOUT_MDM'))
     s = MDM.receive(mdm_timeout)
     result = -2
     while (1):
         if (csd):
             self.tryCSD()
         if (self.config.get('DEBUG_AT') == '1'):
             self.debug.send('DATA AT OUT: ' + atcom)
         s = ''
         MDM.send(atcom, mdm_timeout)
         timer = MOD.secCounter() + timeout
         while (1):
             s = s + MDM.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('DATA AT IN: ' + s[2:])
         trys = trys - 1
         if ((trys <= 0) or (result == 0)):
             break
         MOD.sleep(15)
     return (result, s)
コード例 #2
0
ファイル: gsm.py プロジェクト: suhvm/wrx100_telit_gprs_python
 def sendATData(self, atcom, atres, trys = 1, timeout = 1, csd = 1):
     mdm_timeout = int(self.config.get('TIMEOUT_MDM'))
     s = MDM.receive(mdm_timeout)
     result = -2
     while(1):
         if(csd):
             self.tryCSD()
         if(self.config.get('DEBUG_AT') == '1'):
             self.debug.send('DATA AT OUT: ' + atcom)
         s = ''
         MDM.send(atcom, mdm_timeout)
         timer = MOD.secCounter() + timeout
         while(1):
             s = s + MDM.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('DATA AT IN: ' + s[2:])
         trys = trys - 1
         if((trys <= 0) or (result == 0)):
             break
         MOD.sleep(15)
     return (result, s)
コード例 #3
0
 def __init__(self, settings):
     self.timer = MOD.secCounter()
     self.settings = settings
     self.settingsByKey = settingsByKey = self.settings.byKey
     SER.set_speed('300')
     #self.charmParsed = settingsByKey['charm']
     self.name = settingsByKey['name']
     self.i = settingsByKey['id']
     self.serverAddr = settingsByKey['serverAddr']
     self.maxLate = settingsByKey['maxlate']
     self.desc = settingsByKey['desc']
     self.charm = settingsByKey['charm']
     self.mainLoop = None
     print self.timer
     # Komendy odpowiedzialne za komunikacje internetową
     SER.setDSR(0)
     SER.setCTS(0)
     SER.setDCD(0)
     self.time = 0
     self.SMS = SMS(self)
     self.ipAddr = ""
     self.getTime()
     atstart = settingsByKey["atstart"]
     if len(atstart): sendATlist(atstart)
     self.maxSMSinMEM = settingsByKey["sms_limit"]
     MDM.send(self.m_init, 10)
     MDM.receive(20)
コード例 #4
0
    def net(self):
        """	Funkcja Wprowadza komendy AT odpowiedzialne
			za komunikacje internetnetową"""
        b = ""
        i = 0
        a1, a2 = self.m_net
        list = map(\
         (lambda x,y,s=(self.settingsByKey): x + s[y][0] +'"\r'),\
         ('AT#USERID="','AT#PASSW="'),\
         ('gsmuser',"gsmpass")\
        )
        for a in a1, list, a2:
            for c in a:
                MDM.send(str(c), 10)
                i = 0
                while i < 20:
                    b = MDM.receive(10)
                    if not b:
                        i = i + 1
                        MOD.sleep(5)
                        continue
                    print "Network Initializer: ", c
                    isError(b)
                    break
                # self.ipAddr=b[:b.find("\r")]
                else:
                    print "ERROR to receive command responce."
コード例 #5
0
ファイル: 3004conSMSATRUN.py プロジェクト: jamusategui/zjj
def EnviarDatosMET(datos):
 global debug
 res=enviarAT('at#sd=1,0,6444,"192.168.0.1",0,6444,0',150,'CONNECT')
 if (res==1):
  if (debug==1):
   SER.send('\r\nCONECTADO... Pidiendo pagina.')
 elif (debug==1):
  SER.send('\r\nFallo la coneccion al servidor')
  MOD.sleep(10)
  resx = MDM.send('+++',10)
  MOD.sleep(10)
  res=enviarAT('at#sh=1',20,'OK')
  return -1
 res = MDM.send('GET /archivoquerecibedatos.php?id=telit&msg='+datos+' HTTP/1.0\r\n',10)
 res = MDM.send('Host: 192.168.0.1\r\n',10)
 res = MDM.send('\r\n\r\n',10)
 res3 = RecibirDesdeModem(100,'RCV_MSG')
 MOD.sleep(10)
 resx = MDM.send('+++',10)
 MOD.sleep(10)
 res=enviarAT('at#sh=1',50,'OK')
 if (res==1):
  if (debug==1):
   SER.send('\r\nSocket desconectado')
 elif (debug==1):
  SER.send('\r\nNO se pudo desconectar el socket')
  return -1
 if (res3==-1):
  if (debug==1):
   SER.send('\r\nNo se obtuvo la pagina de vuelta.')
  return -1
 elif (res3==1):
  if (debug==1):
   SER.send('\r\nSe obtuvo correctamente la pagina')
  return 1
コード例 #6
0
ファイル: CmdMnger.py プロジェクト: gabrielventosa/avl_so
def ProcessCMD(cmd,number):
    SER.send('Starting remote command operations\r')
    if(cmd.find('REBOOT') != -1):
        msg = 'Rebooting via SMS commnad'
        SER.send(msg)
        SER.send('\r')
        Log.appendLog(msg)
        res = MDM.send('AT#REBOOT\r',0)
        res = MDM.receive(100)
        MOD.sleep(100)

    if(cmd.find('SOFTUPD') != -1):
        res = -1
        while (res == -1):
            res = FTPupdate.Main('updapp.pyo')
            MOD.sleep(10)
        res = MDM.receive(100)
        SER.send('Enabling Script\r')
        res = MDM.send('AT#ESCRIPT="updapp.pyo"\r',0)
        res = MDM.receive(100)
        MOD.sleep(100)
        SER.send('Rebooting\r')
        res = MDM.send('AT#REBOOT\r',0)
        res = MDM.receive(100)

    if(cmd.find('SALDO') != -1):
        SER.send('Requesting SALDO from TAE\r')
        res = SMS.sendSMS('333','SALDO')
        if(res == -1):
            return
        msg = -1
        while (msg == -1):
            SER.send('...Waiting for Message\r')
            msg = SMS.check4SMS()
        data = SMS.ReadMessage(msg)
        SMS.DelMessage(msg)
        if(data['phn'] == 'TAE'):
            SER.send('Message received from TAE\r')
            SER.send('Sending info to:')
            SER.send(number)
            SER.send('\r')
            res = SMS.sendSMS(number,data['sms'])

    if(cmd.find('GPSPOS') !=-1):
        data = gpsinfo.gpsData()
        if (data == -1):
            AI = MDM.send('AT$GPSAI\r',0)
            AI = MDM.receive(25)
            res = SMS.sendSMS(number,AI)
        else:
            pos = 'lat:'+str(data["latitud"])+'long:'+str(data["longitud"])+'nsats:'+data["gpssats"]
            res = SMS.sendSMS(number,pos)
            SER.send('Sending GPS info via SMS\r')
            SER.send('иии:')
            SER.send(pos)
            SER.send('\r')
            
            
        
    return
コード例 #7
0
    def serverCommunication(self,\
      counter = MOD.secCounter,
      read = MDM.read,
      sleep = MOD.sleep
     ):
        """	Funkcja przekazuje komunikacje do funkcji
			parseConfiguration odpowiedzialnej za
			interpretacje konfiguracji."""
        x = ""
        loD = 0
        timeout = counter() + 60
        p = config(self.module)
        while timeout > counter():
            x = read()
            if x == "":
                sleep(10)
                continue
            loD = len(x)
            e = p.parse(x, loD)
            if e == 0: return
            timeout = counter() + 60
        del p
        MDM.send("+++", 10)
        MDM.receive(50)
        MDM.send("AT#SH=1", 10)
        MDM.receive(10)
コード例 #8
0
ファイル: gprs.py プロジェクト: Aktan/Telit-Loader
def sendAT(cmd):
	MDM.send(cmd + '\r', 0)
	res = MDM.receive(30)
	if (res.find('OK') == -1):
		print 'cmd: %s failed: %s' % (cmd, res)
		return 0
	return 1
コード例 #9
0
def sendAT(cmd):
    MDM.send(cmd + '\r', 0)
    res = MDM.receive(30)
    if (res.find('OK') == -1):
        print 'cmd: %s failed: %s' % (cmd, res)
        return 0
    return 1
コード例 #10
0
def gprsIsOn():
    MDM.send('AT#GPRS?\r', 0)
    res = MDM.receive(10)
    print 'GPRS on: ' + res
    if (res.find('1') == -1):
        return 0
    else:
        return 1
コード例 #11
0
ファイル: gprs.py プロジェクト: Aktan/Telit-Loader
def gprsIsOn():
	MDM.send('AT#GPRS?\r', 0)
	res = MDM.receive(10)
	print 'GPRS on: ' + res
	if (res.find('1') == -1):
		return 0
	else:
		return 1
コード例 #12
0
ファイル: GPRS.py プロジェクト: JanusRC/Python
def send_CM(inSTR,connId,timeOut):
    # This function sends a string while in Command Mode
    #   Arguments:
    #   inSTR: String to send
    #   connId: Connection #
    #   timeOut: Amount of time alotted to send
    #
    #   Returns:
    #    0: Pass
    #    1: String argument empty
    #   -1: Exception
    #   -2: Timeout
    
    if (len(inSTR)==0):
        return 1

    try:

        res = MDM.send('AT#SSEND=' + str(connId) + '\r\n', 0)   

        #Start timeout counter        
        timerA = timers.timer(0)
        timerA.start(timeOut)

        prompt = '\r\n> '

        #Start looking for '\r\n>'
        while(1):

            properties.CMD_BUFFER = properties.CMD_BUFFER + MDM.receive(1)      
            pos1 = properties.CMD_BUFFER.find(prompt)   #look for prompt characters
            if (pos1>=0):
                properties.CMD_BUFFER = properties.CMD_BUFFER[0:pos1] + properties.CMD_BUFFER[pos1+len(prompt):len(properties.CMD_BUFFER)]
                res = MDM.send(inSTR, 0)
                res = MDM.sendbyte(0x1a, 0)       
                
                tempread = ''
                res = ''
                while(1):
                    tempread = MDM.read()
                    if (tempread != ''):
                        res = res + tempread

                    if (res.find('OK')>=0):
                        return (0)    #Pass
                    
                    if timerA.isexpired():
                        return (-2)    #Expired, can't find OK response

            if timerA.isexpired():
                return (-2)    #Expired, no prompt found

    except:
        printException("send_CM(" + inSTR + "," + connId + "," + timeOut + ")")
        JANUS_SER.sendUART("Send CM Exception. \r\n")  

    #Would return with something else before this if it passes without exception
    return (-1) 
コード例 #13
0
 def sendSMS(self, number, smstext):
     # Send command for sending message
     a = MDM.send('AT+CMGS="' + number + '"\r', 2)
     # clear receive buffer
     res = MDM.receive(10)
     a = MDM.send(smstext, 2)  # Send body of message
     # this terminates the message and sends it
     a = MDM.sendbyte(0x1A, 2)  # terminating the message require ctrl-z
     return ()
コード例 #14
0
ファイル: intExp.py プロジェクト: predat0r/GSM
def checkNetwork():
    MOD.sleep(20)
    REC_TIME = 200
    for _ in range(10):
        MDM.send("AT+CREG?\r",0)
        res = MDM.receive(REC_TIME)
        if (res.find('0,1')!=-1): return 1
        else: MOD.sleep(50)
    return 0
コード例 #15
0
ファイル: Module.py プロジェクト: leongersen/afstuderen
def sendEscapeSequence ( ):

    # Module doesn't care if it isn't in data mode
    # Must sleep AT LEAST  1 sec before and after escape sequence
    MOD.sleep(12)
    MDM.send("+++", 5)
    MOD.sleep(12)

    timeout = MOD.secCounter() + 5
    return _target(["OK"], timeout) != 0
コード例 #16
0
def sendEscapeSequence():

    # Module doesn't care if it isn't in data mode
    # Must sleep AT LEAST  1 sec before and after escape sequence
    MOD.sleep(12)
    MDM.send("+++", 5)
    MOD.sleep(12)

    timeout = MOD.secCounter() + 5
    return _target(["OK"], timeout) != 0
コード例 #17
0
ファイル: main.py プロジェクト: darksv/garbage
def write_registers(start_reg, *data):
    SER2.send('writing: %02x %r\r\n' % (start_reg, data))

    MDM.send(
        'AT#I2CWR=%d,%d,%02x,%02x,%d\r' %
        (GPIO_SDA, GPIO_SCL, CODEC_ADDR, start_reg, len(data)), 0)
    MDM.send(''.join(hex(x)[2:].zfill(2) for x in data), 0)
    MDM.sendbyte(0x1a, 0)

    return wait_for_response()
コード例 #18
0
ファイル: main.py プロジェクト: predat0r/GSM
def check_network():
    MOD.sleep(20)
    for _ in range(10):
        MDM.send("AT+CREG?\r",0)
        res = MDM.receive(200)
        print 'check registration'
        if res.find('0,1') != -1:
            print 'registration ok'
            return 1
        else: MOD.sleep(50)
    return 0
コード例 #19
0
    def __init__(self, module):
        self.allowedNumbers = ["+48796752703", "+48601593746"]

        MDM.send('ATE0\r', 2)
        self.prepare()
        self.messageFlag = 0
        self.messages = {}
        self.messagePos = ""
        module.add_operation("SMSCHECK", lambda module,SMS = self: \
         SMS.smsCheck(module) \
        )
コード例 #20
0
ファイル: Module.py プロジェクト: leongersen/afstuderen
def _command (command, timeout = 5):

    # Clear input buffer before reading
    MDM.receive(1)

    MDM.send(command, 5)
    MDM.send(CRLF, 5)

    #SER.send("%s \n" % (command))

    return MOD.secCounter() + timeout
コード例 #21
0
ファイル: 3004conSMSATRUN.py プロジェクト: jamusategui/zjj
def enviarAT(comando,timeout,respuesta_esp):
 comando_aux=comando
 comando_aux=comando_aux.replace('\n',"(N)")
 comando_aux=comando_aux.replace('\r',"(R)")
 global debug
 if (debug==1):
  SER.send("\r\nout:"+comando_aux)
 res_envio=MDM.send(comando,20)
 res_envio=MDM.send('\r\n',20)
 respuesta=RecibirDesdeModem(timeout,respuesta_esp)
 return respuesta
コード例 #22
0
def _command(command, timeout=5):

    # Clear input buffer before reading
    MDM.receive(1)

    MDM.send(command, 5)
    MDM.send(CRLF, 5)

    #SER.send("%s \n" % (command))

    return MOD.secCounter() + timeout
コード例 #23
0
def sendCmd(cmd, value, waitfor):
    if (value != ""):
        cmd = cmd + '='
    else:
        cmd = cmd + '\r'
    res = MDM.send(cmd, 0)
    if (value != ""):
        res = MDM.send(value, 0)
        res = MDM.send('\r', 0)
    if (waitfor > 0):
        res = MDM.receive(waitfor)
    return res
コード例 #24
0
ファイル: scmd.py プロジェクト: gabrielventosa/avl_so
def sendCmd(cmd,value,waitfor):
	if (value != ""):
		cmd = cmd + '='
	else:
		cmd = cmd + '\r'
	res = MDM.send(cmd, 0)
	if (value != ""):
		res = MDM.send(value, 0)
		res = MDM.send('\r', 0)
	if (waitfor > 0):
		res = MDM.receive (waitfor)
	return res
コード例 #25
0
def at_command(command, win="OK", fail="ERROR", delay=10):
  # Send the command
  MDM.send(command + '\r', 5)
  # Wait for the response
  for i in range(delay):
    # Listen to serial port for click
    res = MDM.receive(1)
    # See what happened
    if res.find(win) > -1:
      return False, res
    if res.find(fail) > -1:
      return True, res
  # Timed out :(
  return True, "Timed out"
コード例 #26
0
ファイル: intExp.py プロジェクト: predat0r/GSM
def sendSMS( number, smstext):#, csca):
    if number=="" or smstext=="" : return 0 # or csca == "" : return 0
    #MDM.send('AT+CSCA='+csca+'r',2)
    #MDM.receive(20)
    MDM.send('AT+CMGF=1\r',2)
    MDM.receive(20)
    a = MDM.send('AT+CMGS="' + number + '"\r', 2)
    res = MDM.receive(10)          
    a = MDM.send(smstext, 2)
    a = MDM.sendbyte(0x1A, 2)
    a=''
    while a=='':
        a = MDM.receive(20)
    return ( a.find('OK')!=-1 )
コード例 #27
0
ファイル: GPRS.py プロジェクト: JanusRC/Python
def send_CM(inSTR, connId, timeOut):

    ## TWH - 09/16/2009
    ## Need to determine to timeout for this command

    if len(inSTR) == 0:
        return 1

    try:

        res = MDM.send("AT#SSEND=" + str(connId) + "\r\n", 0)

        # Start timeout counter
        timerA = timers.timer(0)
        timerA.start(timeOut)

        prompt = "\r\n> "

        # Start looking for '\r\n>'
        while 1:

            properties.CMD_BUFFER = properties.CMD_BUFFER + MDM.receive(1)
            pos1 = properties.CMD_BUFFER.find(prompt)  # look for prompt characters
            if pos1 >= 0:
                properties.CMD_BUFFER = (
                    properties.CMD_BUFFER[0:pos1]
                    + properties.CMD_BUFFER[pos1 + len(prompt) : len(properties.CMD_BUFFER)]
                )
                res = MDM.send(inSTR, 0)
                res = MDM.sendbyte(0x1A, 0)

                res = ""
                tmpByte = -1
                while 1:
                    tmpByte = MDM.readbyte()
                    if tmpByte != -1:
                        res = res + tmpByte

                    if res.find("\r\nOK\r\n") >= 0:
                        return 0
                    if timerA.isexpired():
                        return -2

            if timerA.isexpired():
                return -2

    except:
        printException("send_CM()")

    return -3
コード例 #28
0
 def getMessage(self, msgid):
     msg = self.messages.get(msgid)
     if msg: return msg
     MDM.receive(10)
     MDM.send('AT+CMGR=' + str(msgid) + '\r', 2)
     SMScontent = ""
     t = 0
     while not SMScontent:
         SMScontent = MDM.receive(15)
         if t >= 5:
             print "[SMS] Cannot get message number", msgid, "\r"
             return ""
         t = t + 1
     self.messages[msgid] = SMScontent
     return SMScontent
コード例 #29
0
ファイル: SOCKET_HE910.py プロジェクト: JanusRC/Python
def exitDataMode():

    rtnList = [-1,-1]    #[return status,return data]
    # return status:
    #   -1:    Exception occurred
    #    0:    No errors occurred, no return data
    #    1:    No errors occurred, return data

    try:
        #Exit data mode

        ##Lookup the Escape Sequence Guard Time
        ## Future Use
        
        # Delay to meet Escape Sequence Guard Time
        ## Remove Hard Coded Escape Sequence Guard Time
        time.sleep(1)
        
        #Start timeout counter 
        start = time.time() 

        ##Lookup the Escape Sequence
        ## Future Use
        
        #Sending +++
        ## Remove Hard Coded Escape Sequence
        rtnList[1] = mySER.send('+', 10)
        rtnList[1] = mySER.send('+', 10)
        rtnList[1] = mySER.send('+', 10)        

        #Wait for response
        rtnList[1] = ''
        while rtnList[1].find("OK") <= -1:
            rtnList += mySER.read()
            if (time.time() - start) > 20:
                rtnList[0] = -2
                break

        if ((rtnList[0] != -2) and len(rtnList[1] > 0)):
            rtnList[0] = 0

    except:
        print sys.exc_info()
        rtnList[0] = -1

    print rtnList[1]

    return rtnList
コード例 #30
0
ファイル: SMS_HE910.py プロジェクト: JanusRC/Python
def sendSMS(theSmsMsg,theDestination,theTerminator,retry,timeOut):
#This function sends an SMS Message

  # Input Parameter Definitions
  #   theSmsMsg: The text SMS Message
  #   theTerminator: string or character at the end of AT Command
  #   retry:  How many times the command will attempt to retry if not successfully send 
  #   timeOut: number of [1/10 seconds] command could take to respond

    try:

        rtnList = [-1,-1]    #[return status,return data]
        # return status:
        #   -2:    Timeout
        #   -1:    Exception occurred
        #    0:    No errors occurred, no return data
        #    1:    No errors occurred, return data        

      #Note that the 145 being sent in with the destination address is the "type" of destination address, with 145 including a "+" for international
        while (retry != -1):

            rtnList[1] = MDM.send('AT+CMGS="' + str(theDestination) + '",145', 0)
            rtnList[1] = MDM.sendbyte(0x0d, 0)
            rtnList = ATC.mdmResponse('\r\n>', timeOut)

            rtnList[1] = MDM.send(theSmsMsg, 0)
            rtnList[1] = MDM.sendbyte(0x1a, 0)

            #Wait for AT command response
            rtnList = ATC.mdmResponse(theTerminator, timeOut)
              
            #Did AT command respond without error?
            pos1 = rtnList[1].rfind(theTerminator,0,len(rtnList[1]))
            if (pos1 != -1):
              retry = -1
              rtnList = ATC.parseResponse(rtnList[1])
            else:
              retry = retry - 1
     
        rtnList[0] = 0  #no error, no data  

  #If the function fails to find the proper response to the SMS send ('OK<cr><lf>') then we receive a timeout string: 'timeOut'  
    except:
        print sys.exc_info()
        rtnList[0] = -1


    return rtnList
コード例 #31
0
def sendAndCheck(command="AT\r",
                 commit="OK",
                 s=10,
                 retryR=3,
                 retryS=1,
                 timeout=5):
    """
		Funkcja wysyła komendy AT oraz sprawdza ich
		wartość zwrotną. Wrazie nietrzymania wartości
		zwrotnej funkcja ponawia próbe jej odebrania.
		Wrazie przekroczenie limitu prób odebrania
		wartości zwrotnej ("retryR" razy). Funkcja
		ponawia próbe wywołania komendy AT (retryS razy)
	"""
    i = 0
    c = e = None
    while i < retryS:
        MDM.receive(1)
        # if a[:-1]!="\r": a+="\r"
        e = MDM.send(command, s)
        for a in range(0, retryR):
            c = MDM.receive(10)
            if c.find(commit) > -1: return 1
            MOD.sleep(timeout)
        i = i + 1
    return 0
コード例 #32
0
ファイル: watchdog.py プロジェクト: teleofis/RX608SimSwitcher
def sendAT(request, response="OK", timeout=3):
    MDM.send(request + "\r", 2)
    result = -2
    data = ""
    timer = MOD.secCounter() + timeout
    while MOD.secCounter() < timer:
        rcv = MDM.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)
コード例 #33
0
def exitSocketDataMode():

    try:
        #Exit data mode
        delaySec(11)         ##this time is based on esc sequence guard time
        #Start timeout counter        
        timerA = timers.timer(0)
        timerA.start(20)

        #Sending +++
        print 'Sending Data Mode escape sequence'
        res = MDM.send('+++', 10)


        #Wait for response
        res = ''
        while ((res.find("OK")<=-1) and (res != 'timeOut')):
            MOD.watchdogReset()
            res = res + MDM.receive(50)

            pass            
            if timerA.isexpired():
                res = 'timeOut'

    except:
        print 'Script encountered an exception.'
        print 'Exception Type: ' + str(sys.exc_type)
        print 'MODULE -> ATC'
        print 'METHOD -> exitSocketDataMode()'

    print res

    return res
コード例 #34
0
ファイル: SMSHandler.py プロジェクト: sumalla/car-tracker
def sendSMS(NUMBER, SMSText):
	TIMEOUT_CMD = 50
	Helper.writeLog('Starting sendSMS\r\n')
	
	res = Helper.sendCmd('AT+CMGF', '1', TIMEOUT_CMD) # select text format type
	Helper.writeLog('Finished AT+CMGF\r\n')
	
	res = Helper.sendCmd('AT+CNMI', '2,1', TIMEOUT_CMD) # alarm indicators
	Helper.writeLog('Finished AT+CNMI\r\n')
	
	res = Helper.sendCmd('AT+CMGS', NUMBER, TIMEOUT_CMD) # send the message without storing it
	Helper.writeLog('Finished AT+CMGS\r\n')
	
	if (res.find('>') == -1):
		return -1
	else:
		res = MDM.send(SMSText, 0)
		Helper.writeLog('Finished sending SMSText\r\n')
		
		res = MDM.sendbyte(0x1a, 0)
		Helper.writeLog('Finished CTRL+Z\r\n')
		
		for i in range(6):
			res=MDM.read()
			if(res.find("OK")!=-1):
				Helper.writeLog('Found and returning\r\n')
				return 1
			else:
				MOD.sleep(300)
		
		Helper.writeLog('REturning -1\r\n')
		return -1
コード例 #35
0
 def __init__(self, api=None, maxPS=512):
     self.api = api
     if api is MDM:
         self.isMDM = 1
         self.isSER = 0
         self.name = "MDM"
         self.send = lambda b: MDM.send(b, 1)
         self.alive = self.MDM_connection_alive
     else:
         self.isSER = 1
         self.isMDM = 0
         self.name = "SER"
         self.limit = 256
         self.alive = lambda: 1
         self.send = lambda b: SER.send(b)
     self.maxPS = maxPS
     self.baudSec = 0
     self.baud = None
     self.isMDM = 0
     self.baudId = "-1"
     self.b = ""
     self.ex = 0
     self.p = 0
     self.c = 0
     self.name = ""
     self.limit = 1024
     self.l = 0
     self.reset = 0
     self.nextInterface = None
コード例 #36
0
ファイル: main.py プロジェクト: teleofis/Watchdog
def sendAT(request, response, timeout = 2):
    MDM.send(request + '\r', 2)
    result = -2
    data = ''
    timer = MOD.secCounter() + timeout
    while(MOD.secCounter() < timer):
        rcv = MDM.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)
コード例 #37
0
def makeRequest(path, content):

    MDM.receive(1)

    message = ("POST %s HTTP/1.1\n"
               "Host: %s\n"
               "Content-Type: application/json\n"
               "Content-Length: %s\n"
               "\n"
               "%s") % (path, CONNECTED_HOST, len(content), content)

    MDM.send(message, 5)
    MDM.send(CRLF, 5)

    response = receiveReponse()

    return response
コード例 #38
0
ファイル: Module.py プロジェクト: leongersen/afstuderen
def makeRequest ( path, content ):

    MDM.receive(1)

    message = ("POST %s HTTP/1.1\n"
        "Host: %s\n"
        "Content-Type: application/json\n"
        "Content-Length: %s\n"
        "\n"
        "%s") % (path, CONNECTED_HOST, len(content), content)

    MDM.send(message, 5)
    MDM.send(CRLF, 5)

    response = receiveReponse()

    return response
コード例 #39
0
 def parseConfigLine(self):
     # - Znak "#" powoduje do wprowadznie konfiguracji nastepujacej po nim
     # - Za wyjątkiem sytuacji w której pd znaku "#" występuje znak "?",
     #	w tej sytuacji moduł wysyła na interfejs konfiguracje w formacie:
     #	<Id>%<Nazwa modułu>%<Opis>%<Harmonogram>
     argsLine = [""]
     charm = []
     argsIn = 0
     isnEnd = 1
     a = ""
     c_now = ""
     forward = self.forward
     m = self.module
     c_now = forward()[1]
     if c_now == "?":
         MDM.send(self.module.getDeviceInfoLine(), 1)
         return
     else:
         print "Parsing properties."
         while (c_now and c_now != ';'):
             a = argsLine[argsIn]
             if c_now == '/' and a:
                 charm.append(argsLine[argsIn])
                 argsLine[argsIn] = ""
             elif c_now == "%":
                 print "Argument: ", a
                 argsIn = argsIn + 1
                 argsLine.append("")
             else:
                 argsLine[argsIn] = a + c_now
             c_now = forward()[1]
         if argsIn:
             m.i[0] = argsLine[0]
             m.name[0] = argsLine[1]
             m.desc[0] = argsLine[2]
         if len(charm) and m.mainLoop:
             m.mainLoop.parseCharmSequence(charm)
         print \
          "id: ", m.i[0],'\r\n',\
          "name: ", m.name[0],'\r\n',\
          "desc: ", m.desc[0],'\r\n',\
          "charm: ", charm,'\r\n',\
          "parsing charm...",'\r\n'
         print "OK"
     return 1
コード例 #40
0
ファイル: main.py プロジェクト: darksv/garbage
def read_registers(start_reg, n):
    SER2.send('reading: %02x %d\r\n' % (start_reg, n))
    MDM.send(
        'AT#I2CRD=%d,%d,%02x,%02x,%d\r' %
        (GPIO_SDA, GPIO_SCL, CODEC_ADDR, start_reg, n), 0)

    data = ''
    time_max = time.time() + 10.0
    while not contains_any(data, 'OK\r', 'ERROR\r') and time.time() < time_max:
        byte = MDM.readbyte()
        if byte != -1:
            data += chr(byte)

    data = data.lstrip()
    if data.startswith('#I2CRD: '):
        return data[8:data.index('\r')]

    return None
コード例 #41
0
ファイル: GPRS.py プロジェクト: JanusRC/Python
def send_CM(inSTR,connId,timeOut):

    if (len(inSTR)==0):
        return 1

    try:

        res = MDM.send('AT#SSEND=' + str(connId) + '\r\n', 0)

        #Start timeout counter        
        timerA = timers.timer(0)
        timerA.start(timeOut)

        prompt = '\r\n> '

        #Start looking for '\r\n>'
        while(1):

            properties.CMD_BUFFER = properties.CMD_BUFFER + MDM.receive(1)      
            pos1 = properties.CMD_BUFFER.find(prompt)   #look for prompt characters
            if (pos1>=0):
                properties.CMD_BUFFER = properties.CMD_BUFFER[0:pos1] + properties.CMD_BUFFER[pos1+len(prompt):len(properties.CMD_BUFFER)]
                res = MDM.send(inSTR, 0)
                res = MDM.sendbyte(0x1a, 0)       

                res = ''
                tmpByte = -1
                while(1):
                    tmpByte = MDM.readbyte()
                    if (tmpByte != -1):
                        res = res + tmpByte

                    if (res.find('\r\nOK\r\n')>=0):
                        return 0
                    if timerA.isexpired():
                        return -2

            if timerA.isexpired():
                return -2

    except:
        printException("send_CM(" + inSTR + "," + connId + "," + timeOut + ")")

    return -3
コード例 #42
0
ファイル: FTPupdate.py プロジェクト: gabrielventosa/avl_so
def getimei():
	res = MDM.send('AT#CGSN\r',0)
	res = MDM.receive(TIMEOUT_MINIMUM)
	SER.send('Device: ')
	SER.send(res)
	SER.send('\r')
	if (res.find(':') == -1):
		return -1
	index = res.find(':')
	return str(res[index+2:index+17])
コード例 #43
0
def sendSMS(theSmsMsg,theDestination,theTerminator,retry,timeOut):
#This function sends an SMS Message

  # Input Parameter Definitions
  #   theSmsMsg: The text SMS Message
  #   theTerminator: string or character at the end of AT Command
  #   retry:  How many times the command will attempt to retry if not successfully send 
  #   timeOut: number of [1/10 seconds] command could take to respond

    try:

        while (retry != -1):
            print 'AT+CMGS="' + str(theDestination) + '",145'
          
            res = MDM.send('AT+CMGS=' + str(theDestination) + ',145', 0)
            res = MDM.sendbyte(0x0d, 0)
            res = mdmResponse('\r\n>', timeOut)
            print res 

            res = MDM.send(theSmsMsg, 0)
            res = MDM.sendbyte(0x1a, 0)

            #Wait for AT command response
            res = mdmResponse(theTerminator, timeOut)

            #Did AT command respond without error?    
            pos1 = res.rfind(theTerminator,0,len(res))
            if (pos1 != -1):
              retry = -1
              res = parseResponse(res)
            else:
              retry = retry - 1

    except:
        print 'Script encountered an exception.'
        print 'Exception Type: ' + str(sys.exc_type)
        print 'MODULE -> ATC'
        print 'METHOD -> sendSMS(' + theSmsMsg + ',' + theDestination + ',' +theTerminator + ',' + retry + ',' + timeOut + ')'

    print res
  
    return res
コード例 #44
0
ファイル: gprs.py プロジェクト: Aktan/Telit-Loader
def initModem():
	if (not sendAT('AT')):
		return 0
	if (not sendAT('AT+IPR=9600')):
		return 0
	if (not sendAT('AT+CMEE=2')):
		return 0
	res = MDM.send('AT+CPIN=1234\r', 0)	# insert your pin
	res = MDM.receive(3)
	# ignore error, maybe pin is already set
	return 1
コード例 #45
0
def initModem():
    if (not sendAT('AT')):
        return 0
    if (not sendAT('AT+IPR=9600')):
        return 0
    if (not sendAT('AT+CMEE=2')):
        return 0
    res = MDM.send('AT+CPIN=1234\r', 0)  # insert your pin
    res = MDM.receive(3)
    # ignore error, maybe pin is already set
    return 1
コード例 #46
0
ファイル: ATC.py プロジェクト: JanusRC/Python
def sendEMAIL(theEmailSubject,theEmailBody,theTerminator,retry,timeOut):
#This function sends email

  # Input Parameter Definitions
  #   theEmailSubject: The text Email Subject
  #   theEmailBody: The text Email Body
  #   theTerminator: string or character at the end of AT Command
  #   retry:  How many times the command will attempt to retry if not successfully send 
  #   timeOut: number of [1/10 seconds] command could take to respond

    try:

        while (retry != -1):
            print 'AT#SEMAIL="' + EMAIL_ADDRESS + '","' + theEmailSubject + '",0'

            res = MDM.send('AT#SEMAIL="' + EMAIL_ADDRESS + '","' + theEmailSubject + '",0', 0)
            res = MDM.sendbyte(0x0d, 0)
            res = mdmResponse('\r\n>', timeOut)
            print res 

            res = MDM.send(theEmailBody, 0)
            res = MDM.sendbyte(0x1a, 0)

            #Wait for AT command response
            while (1):
                res = mdmResponse(theTerminator, timeOut)
              
                #Did AT command respond without error?    
                pos1 = res.rfind(theTerminator,0,len(res))
                if (pos1 != -1):
                    retry = -1
                    res = parseResponse(res)
                else:
                    retry = retry - 1

    except:
        printException("sendEMAIL()")

    print res
  
    return res
コード例 #47
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)
コード例 #48
0
ファイル: ATC_HE910.py プロジェクト: JanusRC/Python
def sendAtCmd(theCommand, theTerminator, timeOut):
# This function sends an AT command to the MDM interface

    # Input Parameter Definitions
    #   theCommand: The AT command to send to MDM interface
    #   theTerminator: string or character at the end of AT Command 
    #   timeOut: number of seconds command could take to respond

    try:

        rtnList = [-1,-1]    #[return status,return data]
        # return status:
        #   -2:    Timeout
        #   -1:    Exception occurred
        #    0:    No errors occurred, no return data
        #    1:    No errors occurred, return data


        #Clear input buffer
        rtnList[1] = 'junk'
        while(rtnList[1] != ''):
            rtnList[1] = mySER.read()

        print 'Sending AT Command: ' + theCommand + "\r\n"
        rtnList[1] = mySER.send(theCommand,2)
        rtnList[1] = mySER.sendbyte(0x0d,2)

        while True:
            #Wait for AT command response
            rtnList = mdmResponse(theTerminator, timeOut)
            if (rtnList[0] == -1) or (rtnList[0] == -2) : return rtnList
            elif rtnList[0] == 1:
                #what happens if res doesn't return data?
                #Did AT command respond without error?
                pos1 = rtnList[1].rfind('ERROR',0,len(rtnList[1]))    
                pos2 = rtnList[1].rfind(theTerminator,0,len(rtnList[1]))
                if ((pos1 != -1) or (pos2 != -1)) :
                    rtnList = parseResponse(rtnList[1])
                    if rtnList[0] == -1: return rtnList
                    elif rtnList[0] == 1:
                        #what happens if res doesn't return data?
                        rtnList[0] = 1
                        break

    except:
        print sys.exc_info()
        rtnList[0] = -1

    print rtnList[1]

    return rtnList
コード例 #49
0
ファイル: RHandler.py プロジェクト: MrZANE42/car-tracker
def writeScript(name, data, hidden, fileSize):
	SER.send('In write script with length = '+str(len(data))+'\r\n')
	SER.send('AT#WSCRIPT=%s,%d\r' % (name,fileSize))
	MDM.send('AT#WSCRIPT=%s,%d\r' % (name,fileSize), 2)
	res = ''
	while 1:
		res = res + MDM.receive(2)
		if res.find('>>>') != -1:
			break
			
	SER.send("1:"+str(res)+"\r\n")
	
	for i in range(1,len(data)-1):
		MDM.send(data[i], 2)
		MOD.sleep(10)
	
	res = ''
	while 1:
		res = res + MDM.receive(2)
		if res.find('OK') != -1 or res.find('ERROR') != -1:
			break

	SER.send("2:"+str(res)+"\r\n")
コード例 #50
0
def writeScript(name, data, hidden, fileSize):
    SER.send('In write script with length = ' + str(len(data)) + '\r\n')
    SER.send('AT#WSCRIPT=%s,%d\r' % (name, fileSize))
    MDM.send('AT#WSCRIPT=%s,%d\r' % (name, fileSize), 2)
    res = ''
    while 1:
        res = res + MDM.receive(2)
        if res.find('>>>') != -1:
            break

    SER.send("1:" + str(res) + "\r\n")

    for i in range(1, len(data) - 1):
        MDM.send(data[i], 2)
        MOD.sleep(10)

    res = ''
    while 1:
        res = res + MDM.receive(2)
        if res.find('OK') != -1 or res.find('ERROR') != -1:
            break

    SER.send("2:" + str(res) + "\r\n")
コード例 #51
0
ファイル: JANUS_SMS.py プロジェクト: JanusRC/Python
def sendSMS(theSmsMsg,theDestination,theTerminator,retry,timeOut):
#This function sends an SMS Message

  # Input Parameter Definitions
  #   theSmsMsg: The text SMS Message
  #   theTerminator: string or character at the end of AT Command
  #   retry:  How many times the command will attempt to retry if not successfully send 
  #   timeOut: number of [1/10 seconds] command could take to respond

  #Note that the 145 being sent in with the destination address is the "type" of destination address, with 145 including a "+" for international
  while (retry != -1):
    print 'AT+CMGS="' + str(theDestination) + '",145'

    res = MDM.send('AT+CMGS="' + str(theDestination) + '",145', 0)
    res = MDM.sendbyte(0x0d, 0)
    res = ATC.mdmResponse('\r\n>', timeOut)
    print res 

    res = MDM.send(theSmsMsg, 0)
    res = MDM.sendbyte(0x1a, 0)

    #Wait for AT command response
    res = ATC.mdmResponse(theTerminator, timeOut)
      
    #Did AT command respond without error?
    pos1 = res.rfind(theTerminator,0,len(res))
    if (pos1 != -1):
      retry = -1
      res = ATC.parseResponse(res)
    else:
      retry = retry - 1
     
    print res

  #If the function fails to find the proper response to the SMS send ('OK<cr><lf>') then we receive a timeout string: 'timeOut'  
  return res
コード例 #52
0
ファイル: SMS.py プロジェクト: gabrielventosa/avl_so
def check4SMS():
	res = scmd.sendCmd('AT+CMGF', '1', 50)
	TIMEOUT_CMD = 20
	timeout = MOD.secCounter() + TIMEOUT_CMD
	timer = timeout - MOD.secCounter()
	data = ''
	MDM.send('AT+CMGL="REC UNREAD"\r',0)
	while ((data.find('OK') == -1) and (timer >0) and (data.find('+CMS ERROR')==-1)):
		SER.send('...Listing SIM UNREAD MESAGESS\r')
		datatmp = MDM.receive(5)
		data = data + datatmp
		timer = timeout - MOD.secCounter()
		wd.feed()

	if (data.find('+CMGL:') == -1):
		SER.send('No new messages\r')
		return -1
	else:
		lindx = data.find('+CMGL: ')
		uindx = data.find(',"REC')
		slot = data[lindx+7:uindx]
		msg = 'New message received and stored on slot: ' + slot + '\r'
		SER.send(msg)
		return slot
コード例 #53
0
 def connectToServer(self, module):
     """Funkcja rozpoczyna komunikacje z serwerem"""
     i = 0
     module.getCSGN()
     MDM.send("AT#SH=1\r", 1)
     MDM.receive(0)
     print module.serverAddr
     ip, port = module.serverAddr[0:2]
     command = "AT#SD=1,0," + port + "," + ip + "\r"
     if sendAndCheck(command, "CONNECT", 5, 5, 5):
         print "--SOCKET OPENED--"
         MDM.send(str("$" + module.CSGN), 1)
         self.serverCommunication()
     else:
         print "Cannot connect to socket"
         print "--SOCKET FAILURE--"
         MDM.send("AT#SH=1", 1)
         MDM.receive(0)
コード例 #54
0
def enableAndReb(fileToExec, Number, MessageIndex):
    #deleteSMS(MessageIndex)
    SER.send('In Save file' + fileToExec + '\r\n')
    SER.send('After renaming file' + fileToExec + '\r\n')
    NUMBER = Number
    SMSText = "I'm going to reboot, enabling the following file: " + fileToExec
    SER.send("enableAndReb: trying to enable and reboot the module\r\n")
    fileName = '"' + fileToExec + '"'
    res = MDM.read()
    res = Helper.sendCmd('AT#ESCRIPT', fileName, 0)
    res = MDM.receive(30)

    if res.find('OK') != -1:
        MOD.sleep(200)
        text = "script qualified :" + fileName + '\r\n'
        SER.send(text + "\r\n")
        res = sendSMS(NUMBER, SMSText)
        MOD.sleep(200)
        res = MDM.send('AT#REBOOT\r', 0)
        MOD.sleep(200)
        SER.send('rebooting\r\n')
        return 1
    else:
        return -1
コード例 #55
0
ファイル: alarm.py プロジェクト: blizok/sms_alarm
def sendSMS(number, smstext):
    if number == "" or smstext == "": return 0
    #text mode setup
    MDM.send('AT+CMGF=1\r', 2)
    MDM.receive(20)
    #Send SMS intialization
    MDM.send('AT+CMGS="' + number + '"\r', 2)
    #"<" waiting
    res = 0
    n = 0
    while n < 10:
        res = MDM.receive(10)
        if res.find(">") > -1:
            break
        else:
            n = n + 1
    #sms text inserting and ctrl+z confirming
    MDM.send(smstext, 2)
    MDM.sendbyte(0x1A, 2)
    #"OK" confirmation waiting
    a = ''
    while a == '':
        a = MDM.receive(20)
    return (a.find('OK') != -1)
コード例 #56
0
def main_loop():
    in_ = ''

    loop_flag = True
    
    global __STM
    global __FIF
    global CONF_READ_TIMEOUT
    global CONF_METER_TO_READ
    global CONF_WATCHDOG_RESET
    global CONF_METERF
    
    start_read = time.time()
    start_wdg = time.time()
    
    try:
        while loop_flag:
            if time.time() - start_wdg > CONF_WATCHDOG_RESET:
                __STM.reset_wdg()
                start_wdg = time.time()
                
            elif time.time() - start_read > CONF_READ_TIMEOUT:
                
                #STM_GO = stm32.STM32()
                #FIF_GO = fif.FIF(STM_GO, usb_log=True)
                __STM.set_led_toggle('YELLOW',1000,1,1)
                
                utils.mqtt_connect(log=True)
                time.sleep(15)
                
                for m in CONF_METER_TO_READ:
                    res = __FIF.read_LE_0xM(int(m), int(CONF_METERF[int(m)-1])) # CONF_METERF indicates phase number
                    
                    if res[0] != 0:
                        utils.mqtt_send('le_0xm_{}'.format(m), res[9])
                        USB0.send('Meter with {} address read out correctly\r\n'.format(m))
                    else:
                        USB0.send('Meter with {} address is not responding\r\n'.format(m))
                    time.sleep(15)
                
                time.sleep(30)
                utils.mqtt_disconnect(log=True)
                
                __STM.set_led('YELLOW','OFF',0)
                start_read = time.time()
                __STM.reset_wdg()
                start_wdg = time.time()
                continue
                
            elif (in_.find('AT++') == -1):
                in_ = in_ + USB0.read()
            else:
                if (in_.find('AT++') != -1):
            
                    if (in_.find('AT++CONFIG?') != -1):
                        # returns whole configuration
                        CONFIG.dump()
                        USB0.send('++CONFIG OK\r\n')
                        in_ = ''
                        start_read = time.time()
                        continue
                    
                    if (in_.find('AT++METACH=') != -1):
                        # command changes meter addr to new one
                        
                        x = in_.find('=')
                        y = ''
                        for ch in in_[x+1:]:
                            if ch != ',':
                                y += ch
                            else:
                                break
                        addr = y
                        
                        x = in_.find(',')
                        y = ''
                        for ch in in_[x+1:]:
                            if ch != '\r':
                                y += ch
                            else:
                                break
                        new_addr = y
                        try:
                            res = __FIF.change_addr_LE_0xM(int(addr), int(new_addr))
                            USB0.send('METER ADDR CHANGED: {}\r\n'.format(res))
                        except Exception as e:
                            USB0.send('FATAL ERROR ++METACH: {}\r\n'.format(e))
                            
                        USB0.send('++METACH OK\r\n')
                        in_ = ''
                        start_read = time.time()
                        __STM.reset_wdg()
                        start_wdg = time.time()
                        continue
                    
                    
                    if (in_.find('AT++METTR=') != -1):
                        # command sets meters to read out
                        
                        x = in_.find('=')
                        y = in_.find('\r')
                        z = ''
                        for ch in in_[x+1:y]:
                            z += ch
                        
                        CONFIG.set('METER_TO_READ',z)
                        CONFIG.write()
                        CONF_METER_TO_READ = CONFIG.get('METER_TO_READ').split(',')
                        USB0.send('METER_TO_READ -> {}\r\n'.format(CONF_METER_TO_READ))                   
                        USB0.send('++METTR OK\r\n')
                        in_ = ''
                        start_read = time.time()
                        __STM.reset_wdg()
                        start_wdg = time.time()
                        continue
                    
                    if (in_.find('AT++METERF=') != -1):
                        # command sets meters to read out
                        
                        x = in_.find('=')
                        y = in_.find('\r')
                        z = ''
                        for ch in in_[x+1:y]:
                            z += ch
                        
                        CONFIG.set('METERF',z)
                        CONFIG.write()
                        CONF_METERF = CONFIG.get('METERF').split(',')
                        USB0.send('METERF -> {}\r\n'.format(CONF_METERF))                   
                        USB0.send('++METERF OK\r\n')
                        in_ = ''
                        start_read = time.time()
                        __STM.reset_wdg()
                        start_wdg = time.time()
                        continue
                    
                    if (in_.find('AT++METTEST=') != -1):
                        # command tests the meter read out
                        
                        x = in_.find('=')
                        y = in_.find('\r')
                        addr = int(in_[x+1:y])
                        
                        res = __FIF.read_LE_0xM(int(addr), int(CONF_METERF[addr-1]))
                    
                        if res[0] != 0:
                            USB0.send('Meter with {} address read out correctly\r\n'.format(res))
                        else:
                            USB0.send('Meter with {} address is not responding\r\n'.format(res))
                        
                        USB0.send('++METTEST OK\r\n')
                        in_ = ''
                        start_read = time.time()
                        __STM.reset_wdg()
                        start_wdg = time.time()
                        continue
                    
                    if (in_.find('AT++READTM=') != -1):
                        # command sets meters to read out
                        
                        x = in_.find('=')
                        y = in_.find('\r')
                        z = int(in_[x+1:y])
                        
                        CONFIG.set('READ_TIMEOUT',str(z))
                        CONFIG.write()
                        CONF_READ_TIMEOUT = int(CONFIG.get('READ_TIMEOUT'))
                        USB0.send('READ_TIMEOUT -> {}\r\n'.format(CONF_READ_TIMEOUT))                   
                        USB0.send('++READTM OK\r\n')
                        in_ = ''
                        start_read = time.time()
                        __STM.reset_wdg()
                        start_wdg = time.time()
                        continue
            
            
                    if (in_.find('AT++STM?') != -1):
                        USB0.send('++STM OK\r\n')
                        in_ = ''
                        start_read = time.time()
                        __STM.reset_wdg()
                        start_wdg = time.time()
                        continue
            
                    if (in_.find('AT++MQTT=CONNECT') != -1):
                        utils.mqtt_connect(log=True)
                        USB0.send('++STM OK\r\n') # TODO to change for ++MQTT OK
                        in_ = ''
                        start_read = time.time()
                        __STM.reset_wdg()
                        start_wdg = time.time()
                        continue
            
                    if (in_.find('AT++MQTT=DISCONNECT') != -1):
                        utils.mqtt_disconnect(log=True)
                        USB0.send('++STM OK\r\n')
                        in_ = ''
                        start_read = time.time()
                        __STM.reset_wdg()
                        start_wdg = time.time()
                        continue
            
                    if (in_.find('AT++DWCONN') != -1):
                        res = utils.get_DWCONN()
                        USB0.send('{}\r\n'.format(res[0]))
                        USB0.send('++DWCONN OK\r\n')
                        in_ = ''
                        start_read = time.time()
                        __STM.reset_wdg()
                        start_wdg = time.time()
                        continue
          
                    if (in_.find('AT++STM=') != -1):
                
                        cmd_idx = in_.find('=')+1
                        cmd = in_[cmd_idx:]
                
                        SER.send(cmd, 1)
                        res = utils.SER_receive(2)
                        USB0.send('(++STM OK):' + res)
                        in_ = ''
                        start_read = time.time()
                        __STM.reset_wdg()
                        start_wdg = time.time()
                        continue
  
                    if (in_.find('AT++MODEM=') != -1):
                
                        cmd_idx = in_.find('=')+1
                        cmd = in_[cmd_idx:]
                
                        MDM.send(cmd, 1)
                        res = utils.MDM_receive(2)
                        USB0.send('(++MODEM OK):' + res)
                        in_ = ''
                        start_read = time.time()
                        __STM.reset_wdg()
                        start_wdg = time.time()
                        continue
            
                    if (in_.find('AT++QUIT') != -1):
                        __STM.set_led('RED','OFF',0)
                        USB0.send('++QUIT OK\r\n')
                        in_ = ''
                        loop_flag = False
            
                    else:
                        USB0.send('++OK\r\n')
                        in_ = ''
                        start_read = time.time()
                        __STM.reset_wdg()
                        start_wdg = time.time()
                        continue
        else: 
            USB0.send('MODBUS program has been closed...\r\n')
    except Exception as e:
        USB0.send('FATAL ERROR: main loop {}\r\n'.format(e))
        log('FATAL ERROR: main loop {}\r\n'.format(e))
コード例 #57
0
ファイル: SMS.py プロジェクト: HansKramer/TelitEasyScript
#
#  Author : Hans kramer
#
#    Date : Dec 2014
#
#    Code : SMS 
#

import SER
import MDM
import time


if __name__ == "__main__":
    SER.set_speed('115200', '8N1')

    recipient = "Your Phone"
    message   = "Your message here"

    MDM.send('ATE0\r\n', 10)
    MDM.send('ATZ\r\n', 10)
    MDM.send('AT+CMGF=1\r\n', 10)
    MDM.send('AT+CMGS="' + recipient + '"\r\n', 10)
    MDM.send(message + "\r\n", 10)
    MDM.send(chr(26) + "\r\n", 10)
    SER.send(data + "\r\n")

コード例 #58
0
 def sendATMdm(self, atcom):
     mdm_timeout = int(self.config.get('TIMEOUT_MDM'))
     MDM.send(atcom, mdm_timeout)
     self.debug.send('DATA AT OUT: ' + atcom)
コード例 #59
0
 def sendMdm(self, data):
     MDM.send(data, 50)
     self.debug.send('Sending data to MDM: ' + str(len(data)) + ' bytes')
コード例 #60
0
        tries = tries - 1
        import MDM
        import SER
        import MOD
        import sys
        import instamsg
    except:
        try:
            if (tries == 0):
                # Create __error log for trouble shooting.
                error = ('ioEYE:: Fatal __error.%s %s\r\n' %
                         (str(sys.exc_info()[0]), str(sys.exc_info()[1])))
                f = open('__error.log', 'wb')
                error = error + 'Disabling python script...\r\n'
                f.write(error)
                MDM.send('AT#ESCRIPT=""' + '\r', 5)
        finally:
            if (tries == 0):
                f.close()
                sys.exit()


def start(args):
    instaMsg = None
    try:
        try:
            stdOut, stdErr = sys.stdout, sys.stderr
            logger = Logger()
            sys.stdout = sys.stderr = logger
            options = {'logLevel': instamsg.INSTAMSG_LOG_LEVEL_DEBUG}
            clientId = "525420b0-aa9d-11e4-a4c6-404014d5dd81"