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)
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
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
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)
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)
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)
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
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
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 )
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
def GetData(TIMEOUT_DWNLD): SER.send('Ready to wait for response\r') timeout = MOD.secCounter() + TIMEOUT_DWNLD timer = timeout - MOD.secCounter() HTML_UC_END = '</RESPONSE>' HTML_LC_END = '</response>' data = '' mesg = '' while ((data.find('NO CARRIER') == -1) and (timer >0) ): SER.send('...Downloading\r') datatmp = MDM.receive(5) data = data + datatmp timer = timeout - MOD.secCounter() wd.feed() if(data.find('HTTP/1.1 200') == -1): mesg = 'Update server ERROR: ' + data[0:12] SER.send(mesg) SER.send('\r') SER.send(data) SER.send('\r') data = -1 else: mesg = 'Update server SUCCEFULL: ' + data[0:12] SER.send(mesg) SER.send('\r') Log.appendLog(mesg) return data
def mdmResponse(theTerminator, timeOut): # This function waits for AT Command response and handles errors and ignores unsolicited responses # Input Parameter Definitions # theTerminator: string or character at the end of a received string which indicates end of a response # timeOut: number of seconds command could take to respond try: print 'Waiting for AT Command Response' #Start timeout counter timerA = timers.timer(0) timerA.start(timeOut) #Wait for response res = '' while ((res.find(theTerminator)<=-1) and (res.find("ERROR")<=-1) and (res != 'timeOut')): MOD.watchdogReset() res = res + MDM.receive(10) pass if timerA.isexpired(): res = 'timeOut' except: print 'Script encountered an exception.' print 'Exception Type: ' + str(sys.exc_type) print 'MODULE -> ATC' print 'METHOD -> mdmResponse(' + theTerminator + ',' + timeOut + ')' return res
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
def receiveReponse ( ): timeout = MOD.secCounter() + 10 str = "" length = "" newlinepos = 0 while ( MOD.secCounter() < timeout ): newlinepos = str.find("\n\r") if ( (newlinepos != -1) and not length ): newlinepos = newlinepos + 2 pos = str.find("Content-Length:") + 15 while ( str[pos] != '\n' ): length = "%s%s" % (length, str[pos]) pos = pos + 1 length = int(length) + newlinepos else: MOD.sleep(5) str = str + MDM.receive(1) if ( length and len(str) >= length ): return str[newlinepos:(newlinepos+length)] return 0
def mdmResponse(theTerminator, timeOut): # This function waits for AT Command response and handles errors and ignores unsolicited responses # Input Parameter Definitions # theTerminator: string or character at the end of a received string that indicates end of a response # timeOut: number of seconds command could take to respond try: print 'Waiting for AT Command Response' #Start timeout counter timerA = timers.timer(0) timerA.start(timeOut) #Wait for response res = '' while ((res.find(theTerminator)<=-1) and (res.find("ERROR")<=-1) and (res != 'timeOut')): MOD.watchdogReset() res = res + MDM.receive(10) pass if timerA.isexpired(): res = 'timeOut' except: printException("mdmResponse()") return res
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
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."
def receiveReponse(): timeout = MOD.secCounter() + 10 str = "" length = "" newlinepos = 0 while (MOD.secCounter() < timeout): newlinepos = str.find("\n\r") if ((newlinepos != -1) and not length): newlinepos = newlinepos + 2 pos = str.find("Content-Length:") + 15 while (str[pos] != '\n'): length = "%s%s" % (length, str[pos]) pos = pos + 1 length = int(length) + newlinepos else: MOD.sleep(5) str = str + MDM.receive(1) if (length and len(str) >= length): return str[newlinepos:(newlinepos + length)] return 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
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
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
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)
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)
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
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 ()
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])
def delAll(): res = MDM.send("AT+CMGF=1\r", 0) res = MDM.receive(3) res = MDM.send("AT+CNMI=2,1\r", 0) res = MDM.receive(3) if res.find("OK") != -1: print "OK for AT+CNMI=2,1" else: print "ERROR for AT+CNMI=2,1" # SIM status control - to avoid the 'sim busy' error print "SIM Verification Cycle" a = MDM.send("AT+CPBS?\r", 0) SIM_status = MDM.receive(10) if SIM_status.find("+CPBS") < 0: print "SIM busy! Please wait!\n" while SIM_status.find("+CPBS:") < 0: a = MDM.send("AT+CPBS?\r", 0) SIM_status = MDM.receive(10) MOD.sleep(2) print "SIM Ready" # receive the list of all sms MDM.send('AT+CMGL="ALL"\r', 0) smslist = "" MemSMS = MDM.receive(20) smslist = MemSMS while MemSMS != "": MemSMS = MDM.receive(20) smslist = smslist + MemSMS # listsms = MemSMS.splitlines() listsms = smslist.split("\n") listIndex = [] # the list of index to delete for string in listsms: if string.find("+CMGL:") != -1: # find the index of each sms start = string.find(":") end = string.find(",") myindex = string[(start + 1) : end] myindex = myindex.strip() listIndex.append(myindex) print string if listIndex == []: print "No SMS in SIM" # delete all sms for index in listIndex: print "Deleting sms index: " + index MDM.send("AT+CMGD=", 0) MDM.send(index, 0) MDM.send("\r", 0) res = MDM.receive(20) res = res.replace("\r\n", " ") print res return 1
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
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
def isMessage(self): res = MDM.receive(5) a = res.find('+CMTI: "SM",') if (a != -1): firstdigit_pos = a + 12 self.messagePos = res[firstdigit_pos:-2] print "Message id is", self.messagePos self.messageFlag = 1 return 1 else: self.messageFlag = 0 return 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
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
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")
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"
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
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")
def _target(targets, timeout): res = "" while (MOD.secCounter() < timeout): res = res + MDM.receive(1) index = 0 for target in targets: if (res.rfind(target) != -1): return [index, res] index = index + 1 return 0
def _target (targets, timeout): res = "" while ( MOD.secCounter() < timeout ): res = res + MDM.receive(1) index = 0 for target in targets: if ( res.rfind(target) != -1 ): return [index, res] index = index + 1 return 0
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)
def RecibirDesdeModem(timeout,respuesta_esp): global debug data="" while 1: nueva_data=MDM.receive(timeout) data=data+nueva_data respuesta_aux=data respuesta_aux=respuesta_aux.replace('\n'," ") respuesta_aux=respuesta_aux.replace('\r'," ") if (len(nueva_data)==0): if (debug==1): SER.send("\r\nin (Timeout):"+respuesta_aux) return -1 if (data.find(respuesta_esp)!=-1): if (debug==1): SER.send("\r\nin (OK):"+respuesta_aux) return 1 return 0
def check4SMS(): Helper.sendCmd('AT+CMGF','1', 50) data= '' data = Helper.sendCmd('AT+CMGL','"ALL"',20) smslist='' #listen to what the telit says with a timeout of 20 smslist = smslist + data while data != '': data = MDM.receive(20) smslist = smslist + data smsarray = [] lines = smslist.split('+CMGL:') if len(lines) > 1: for i in range(1,len(lines)): smsarray.append(parseSMS(lines[i])) return smsarray
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
def exitDataMode(): 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 delaySec(1) #Start timeout counter timerA = timers.timer(0) timerA.start(20) ##Lookup the Escape Sequence ## Future Use #Sending +++ ## Remove Hard Coded 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: printException("exitDataMode()") print res return res
def sendAtCmd(theCommand, theTerminator, retry, 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 # 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: #Clear input buffer res = "junk" while(res != ""): res = MDM.receive(1) while (retry != -1): print 'Sending AT Command: ' + theCommand res = MDM.send(theCommand, 0) res = MDM.sendbyte(0x0d, 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' + '\r' print 'METHOD -> sendAtCmd(' + theCommand + ',' +theTerminator + ',' + retry + ',' + timeOut + ')' + '\r' print res return res
def chat(Host,Script,data): SER.send('Ready to negotiate with server\r') HTTP_ver = " HTTP/1.0" res = MDM.send('GET ',0) #res = MDM.send(Host,0) res = MDM.send(Script,0) res = MDM.send(data,0) res = MDM.send(HTTP_ver,10) res = MDM.sendbyte(0x0d,10) res = MDM.sendbyte(0x0a,10) res = MDM.send('Host: ',0) res = MDM.send(Host,0) res = MDM.sendbyte(0x0d,10) res = MDM.sendbyte(0x0a,10) res = MDM.sendbyte(0x0d,10) res = MDM.sendbyte(0x0a,10) resc = GetData(180) res = MDM.receive(30) return resc
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
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
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
def getCSGN(self): MDM.receive(0) MDM.send('AT+CGSN\r', 10) MOD.sleep(10) a = MDM.receive(10) self.CSGN = a[2:17]
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # ################## Modules ################## import MDM # Use AT command interface import MOD # Use build in module import SER # Use serial import CONFIG # Configurations import FUNC # Functions conf = CONFIG.config # settings --------------------------------- # 0 flow control OFF res = MDM.send('AT&K0\r', 0) res = MDM.receive(10) # Konfiguration laden --------------------------------------------------- res = CONFIG.initConfig() SER.set_speed(conf['COM'],'8N1') a = SER.send('\r\n***************************************************************************') a = SER.send('\r\n* Start Terminal Connection - Triptec Service *') a = SER.send('\r\n***************************************************************************\r\n') a = SER.send('\r\n- wait for connection to network ----------------\r\n') r = FUNC.openGPRS(conf['PIN_SIM'],conf['APN'],conf['GPRS_USER'],conf['GPRS_PASS']) #openGPRS(P,A,GU,GP) a = FUNC.setGPIO(CONFIG.statLED,1) a = SER.send('\r\n\r\n- wait for data input ----------------\r\n') # start Schleife -------------------------------------------------------- while 1: