Example #1
0
def DelMessage(number):
	SER.send('Deleting Message on slot: ')
	SER.send(number)
	SER.send('\r')
	res = scmd.sendCmd('AT+CMGF', '1', 10)
	res = scmd.sendCmd('AT+CMGD', number, 10)
	return
Example #2
0
def ReadMessage(number):
	res = scmd.sendCmd('AT+CMGF', '1', 10)
	res = scmd.sendCmd('AT+CMGR', number, 5)
	msg = res.split(',')
	phn_len = len(msg[1])
	phn = msg[1]
	data = {}
	data['phn'] = phn[1:phn_len-1]
	res = res[2:]
	sms_start = res.find('\r\n')
	sms_end = res.rfind('OK')
	data['sms'] = res[sms_start+2:sms_end-2]
	return data
Example #3
0
def getBattery():
	res = scmd.sendCmd('AT+CBC','',10)
	if (res == -1):
		return -1
	batt = res.split(',')
	battlife = batt[1]
	return battlife[0:3]
Example #4
0
def uptime():
	res = scmd.sendCmd('AT+CCLK?','',10)
	if (res == -1):
		return -1
	res = res.split(',')
	res = str(res[1])
	return res[0:8]
Example #5
0
def sendSMS(NUMBER, SMSText):
	TIMEOUT_CMD = 50
	res = scmd.sendCmd('AT+CMGF', '1', TIMEOUT_CMD) # select text format type
	res = scmd.sendCmd('AT+CNMI', '2,1', TIMEOUT_CMD) # alarm indicators
	res = scmd.sendCmd('AT+CSMP', '17,167,0,0', TIMEOUT_CMD) # select message parameter
	res = scmd.sendCmd('AT+CMGS', NUMBER, TIMEOUT_CMD) # send the message without storing it
	if (res.find('>') == -1):
		return -1
	else:
		res = MDM.send(SMSText, 0)
		res = MDM.sendbyte(0x1a, 0)
		for i in range(6):
			res=MDM.read()
			if(res.find("OK")!=-1):
				return 1
			else:
				MOD.sleep(300)
		return -1
Example #6
0
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
Example #7
0
def getimei():
	res = scmd.sendCmd('AT#CGSN','',10)
	if (res == -1):
		return -1
	index = res.find(':')
	return str(res[index+2:index+17])
Example #8
0
def Mainloop():
	MAX_ERRORS = 3
	UPDATE_TIME = 3600
	TIMEOUT_CMD = 500

	wd.feed()
	
	res = SER.set_speed('9600')
	imei = utils.getimei()
	time = Log.uptime()
	smsmsg = time + ' Starting Unit: ' + imei
	res = MDM.receive(20)
	res = scmd.sendCmd('AT+CMGF', '1', 50)
	res = 1
	
	if(res != 1):
		Log.ReportError('Error Sending Init MSG')
	else:
		msg= 'Starting Unit:' + imei
		Log.appendLog(msg)
		printdbg.printSER(msg)
		

	res = scmd.sendCmd('at+cfun','5',10)
	serv_data = -1
	
	while 1:	
		hname = gprs.gethname()
		printdbg.printSER(hname)
		NUpdate = timers.timer(0)
		NUpdate.start(3)
		print "Ready to start main loop"
		Mto = timers.timer(0)
		Mto.start(120)
		while 1:
			wd.feed()
			printdbg.printSER("Doing GPS")
			data =gpsinfo.gpsData() 
			if data == -1:
				errmsg = "GPS Error"
				printdbg.printSER("GPS ERROR")
				#Log.ReportError(errmsg)
###############################################################################
###########STATIC UPDATE ROUTINE###############################################
###############################################################################
			try:
				if (NUpdate.isexpired() and data != -1):
					print "ready to static update"
					Log.ReportError('Doing timeout Update')
					data["dyn"] = "0"
					Chronos.set_LockFlag()
					res = gprs.updateloop(hname,data,MAX_ERRORS)
					gp = gprs.disGPRS()
					NUpdate.start(3600)
					if res == -1:
						break
					serv_data = data
			except (Exception, StandardError, SystemError, RuntimeError):
				msg = 'Expception in Static Update: '
				Log.appendLog(msg)
				print "exception in static update"

###############################################################################
############END OF STATIC UPDATE ROUTINE#######################################
###############################################################################				
				
			data = gpsinfo.gpsData()
			if data == -1:
				errmsg = "GPS Error"
				#Log.ReportError(errmsg)
###############################################################################
###############DYNAMIC UPDATE ROUTINE##########################################
###############################################################################
			try:
				if serv_data != -1 and data!= -1 and \
				    utils.dist(serv_data["latitud"],data["latitud"],serv_data["longitud"],data["longitud"]) > 5000:
					Log.ReportError('Dynamic Routine Update')
					data["dyn"] = "1"
					res = gprs.updateloop(hname,data,MAX_ERRORS)
					if res == -1:
						Log.ReportError('Error in updateloop')
						break
					serv_data = data
					NUpdate.start(300)

			except (Exception, StandardError, SystemError, RuntimeError):
				msg = 'Expception in Dynamic Update '
				Log.appendLog(msg)
				print "exception in dynamic update"
				
##############################################################################
##############END OF DYNAMIC UPDATE ROUTINE###################################
##############################################################################
##############################################################################
##############Start revision of wireless alert##		
			try:
				SER.send('SWICHT_LED\r')
				if(Chronos.check_PannicFlag() == 1):
					print 'Doing Pannic Update'
					data["dyn"] = "2"
					res = gprs.updateloop(hname,data,MAX_ERRORS)
					if res == -1:
						Log.ReportError('Error in updateloop')
						break
					else:
						Chronos.reset_PannicFlag()
					serv_data = data
					NUpdate.start(10)

				if(Chronos.check_LockFlag() == 0 and serv_data["dyn"] == "1"):
					data["dyn"] = "3"
					res = gprs.updateloop(hname,data,MAX_ERRORS)
					if res == -1:
						Log.ReportError('Error in updateloop')
						break
					serv_data = data
					NUpdate.start(10)
				

			except (Exception, StandardError, SystemError, RuntimeError):
				msg = 'Expception in Dynamic Update '
				Log.appendLog(msg)

##############################################################################
###############SMS CHECK######################################################
			try:
				msg = SMS.check4SMS()
				if(msg != -1):
					data = {}
					data = SMS.ReadMessage(msg)
					SER.send('New message from:')
					SER.send(data['phn'])
					SER.send('\r')
					SER.send('SMS Contents:')
					SER.send(data['sms'])
					SER.send('---END OF SMS\r')
					SMS.DelMessage(msg)
					CmdMnger.ProcessCMD(data['sms'],data['phn'])
					
			except (Exception, StandardError, SystemError, RuntimeError):
				msg = 'Expception in SMS'
				Log.appendLog(msg)
				print "exception in SMS check"

##############################################################################
###############SMS Delete######################################################
			try:
				if (Mto.isexpired()):
					res = DelSMS.delAll()
					Mto.start(432000)
				
			except (Exception, StandardError, SystemError, RuntimeError):
				msg = 'Expception in SMS'
				Log.appendLog(msg)
				print "exception in SMS delete"
				
	return