def openSocket(addr,port,sockNum,userID,userPassword,protocol,RUN_MODE): #Function Open a socket and responds with CONNECT/NO CARRIER/ERROR try: #Close Socket res = sendAtCmd('AT#SS',properties.CMD_TERMINATOR,0,20) if (res!="#SS: 1,0"): res = sendAtCmd('AT#SH=1',properties.CMD_TERMINATOR,0,20) if (res=='ERROR'): return #Activate PDP if needed res = sendAtCmd('AT#SGACT?',properties.CMD_TERMINATOR,0,20) if (res!="#SGACT: 1,1"): delaySec(1) res = sendAtCmd('AT#SGACT=1,1,"' + str(userID) + '","' + str(userPassword) + '"' ,properties.CMD_TERMINATOR,0,180) DEBUG.sendMsg(res + '\r\n',RUN_MODE) if (res=='ERROR'): return #Open Socket to Server if (str(protocol)=='TCPIP'): res = sendAtCmd('AT#SD=1,0,' + port + ',"' + addr + '",0','CONNECT\r\n',0,180) else: res = sendAtCmd('AT#SD=1,1,' + port + ',"' + addr + '",0,5559','CONNECT\r\n',0,180) except: print 'Script encountered an exception.' print 'Exception Type: ' + str(sys.exc_type) print 'MODULE -> ATC' print 'METHOD -> openSocket(' + addr + ',' + port + ',' + sockNum + ',' + userID + ',' + userPassword + ',' + protocol + ')' return res
def initGPRS (PDPindex,APN,userID,userPassword,RUN_MODE): try: #Define GPRS Settings, MUST change APN String in script for your Carrier Specific setting res = sendAtCmd('AT+CGDCONT=' + str(PDPindex) + ',"IP","' + str(APN) + '","0.0.0.0",0,0' ,properties.CMD_TERMINATOR,0,20) #How long does system wait before sending undersized packet measured in 100ms settings res = sendAtCmd('AT#DSTO=10' ,properties.CMD_TERMINATOR,0,20) #Define Min/required Quality of Service res = sendAtCmd('AT+CGQMIN=1,0,0,0,0,0' ,properties.CMD_TERMINATOR,0,20) res = sendAtCmd('AT+CGQREQ=1,0,0,3,0,0' ,properties.CMD_TERMINATOR,0,20) #escape guard time, after set time escape sequence is excepted, set in 20ms settings res = sendAtCmd('ATS12=40' ,properties.CMD_TERMINATOR,0,20) #disable the escape sequence from transmitting during a data session res = sendAtCmd('AT#SKIPESC=1' ,properties.CMD_TERMINATOR,0,20) #Set connect timeOuts and packet sizes for PDP#1 and Socket#1 res = sendAtCmd('AT#SCFG=1,1,512,90,100,50' ,properties.CMD_TERMINATOR,0,20) #Activate PDP if needed res = sendAtCmd('AT#SGACT?',properties.CMD_TERMINATOR,0,20) if (res!="#SGACT: 1,1"): delaySec(1) res = sendAtCmd('AT#SGACT=1,1,"' + str(userID) + '","' + str(userPassword) + '"' ,properties.CMD_TERMINATOR,0,180) DEBUG.sendMsg(res + '\r\n',RUN_MODE) if (res=='ERROR'): return except: print 'Script encountered an exception.' print 'Exception Type: ' + str(sys.exc_type) print 'MODULE -> ATC' print 'METHOD -> initGPRS(' + PDPindex + ',' + APN + ',' + res + ')' return
myApp.CIK = '' # <-- Exosite #Reboot system after <entered value> secs if unable to register with a network #Allow at least 5 minutes (300 seconds) MOD.watchdogEnable(300) try: RUN_MODE = 0 test = float(RUN_MODE) #float not implemented in Telit module except: #Running in IDE RUN_MODE = 1 DEBUG.CLS(RUN_MODE) #Clear screen command for VT100 terminals DEBUG.sendMsg("GPSDemo Script has started\r\n",RUN_MODE) #Apply Network Specific settings see myApp.xxxx assignment above if (myApp.NETWORK == "ATT"): #Set module to work on US ATT Network res = ATC.sendAtCmd("AT#ENS?",ATC.properties.CMD_TERMINATOR,3,2) #query ENS setting if (res == "#ENS: 0"): res = ATC.sendAtCmd('AT#ENS=1',ATC.properties.CMD_TERMINATOR,3,2) #sets all ATT requirements MOD.sleep(15) #required to halt Python thread and allow NVM Flash to update res = ATC.sendAtCmd('AT#REBOOT',ATC.properties.CMD_TERMINATOR,3,2) #must reboot to take effect res = ATC.sendAtCmd("AT#SELINT?",ATC.properties.CMD_TERMINATOR,3,2) #query SELINT setting if (res != "#SELINT: 2"): res = ATC.sendAtCmd('AT#SELINT=2',ATC.properties.CMD_TERMINATOR,3,2)#use of most recent AT command set MOD.sleep(15) #required to halt Python thread and allow NVM Flash to update res = ATC.sendAtCmd('AT#REBOOT',ATC.properties.CMD_TERMINATOR,3,2) #must reboot to take effect
def sendEMAIL(theEmailToAddress,theEmailSubject,theEmailBody,theTerminator,userID,userPassword,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: tmpReturn = -1 while (retry != -1): #Activate PDP if needed res = sendAtCmd('AT#SGACT?',properties.CMD_TERMINATOR,0,20) if (res!="#SGACT: 1,1"): delaySec(1) res = sendAtCmd('AT#SGACT=1,1,"' + str(userID) + '","' + str(userPassword) + '"' ,properties.CMD_TERMINATOR,0,180) DEBUG.sendMsg(res + '\r\n',RUN_MODE) if (res=='ERROR'): return tmpReturn print 'AT#EMAILD="' + theEmailToAddress + '","' + theEmailSubject + '",0' res = MDM.send('AT#EMAILD="' + theEmailToAddress + '","' + 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) #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' if((res.find("ERROR") > -1) or (res == 'timeOut')): retry = retry - 1 else: retry = -1 tmpReturn = 0 except: print 'Script encountered an exception.' print 'Exception Type: ' + str(sys.exc_type) print 'MODULE -> ATC' print 'METHOD -> sendEMAIL(' + theEmailToAddress + ',' + theEmailSubject + ',' + theEmailBody + ',' +theTerminator + ',' + retry + ',' + timeOut + ')' print res return tmpReturn