Esempio n. 1
0
        if data != {} and (changed > 0 or
                           ((tt - lastMsg) > G.sendToIndigoSecs or
                            (tt - lastMsg) > 200)):
            lastMsg = tt
            lastData = copy.copy(data)
            try:
                #U.toLog(2, u"sending url: "+unicode(data))
                U.sendURL({"sensors": data})
            except Exception, e:
                U.toLog(-1,
                        u"in Line '%s' has error='%s'" %
                        (sys.exc_traceback.tb_lineno, e),
                        permanentLog=True)
            time.sleep(0.05)

        quick = U.checkNowFile(G.program)

        U.makeDATfile(G.program, data)
        U.echoLastAlive(G.program)

        tt = time.time()
        NSleep = int(sensorRefreshSecs) * 2
        if tt - lastregularCycle > sensorRefreshSecs:
            regularCycle = True
            lastregularCycle = tt

        for n in range(NSleep):
            if quick: break

            readParams()
            time.sleep(0.5)
Esempio n. 2
0
		# perform a device inquiry on bluetooth device #0
		# The inquiry should last 8 * 1.28 = 10.24 seconds
		# before the inquiry is performed, bluez should flush its cache of
		# previously discovered devices
		flt = bluez.hci_filter_new()
		bluez.hci_filter_all_events(flt)
		bluez.hci_filter_set_ptype(flt, bluez.HCI_EVENT_PKT)
		sock.setsockopt( bluez.SOL_HCI, bluez.HCI_FILTER, flt )


		ii = 1000
		while ii>0:
			ii-=1
			tt=time.time()
			quick = U.checkNowFile(sensor)				  
			if tt - paramCheck >2:
				newParametersFile = readParams(False)
				paramCheck=time.time()
				if newParametersFile: 
					quick = True

			## get new data
#			 allBeaconMSGs = parse_events(sock, collectMsgs,offsetUUID,batteryLevelPosition,maxParseSec ) # get the data:  get up to #collectMsgs at one time
			allBeaconMSGs=[]
			try:	
				pkt = sock.recv(255)
				errCount = 0
			except	Exception, e:
				U.toLog(-1,u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e),permanentLog=True)
				errCount += 1
Esempio n. 3
0
	try:
		tt = time.time()
		if sensor in sensors:
			skip =False
			
		if sensor in sensors:
			for devId in sensors[sensor]:
				if devId not in lastValue: lastValue[devId] = copy.copy(lastValueDefault)
				if devId not in G.threshold: G.threshold[devId] = thresholdDefault
				values = getValues(devId)
				lastValue =U.checkMGACCGYRdata(
					values,lastValue,testDims,testCoords,testForBadSensor,devId,sensor,quick,
					sumTest=sumTest,singleTest=singleTest)

		loopCount +=1

		quick = U.checkNowFile(G.program)				 
		U.echoLastAlive(G.program)

		tt= time.time()
		if tt - lastRead > 5.:	
			readParams()
			lastRead = tt
		if not quick:
			time.sleep(G.sensorLoopWait)
		
	except	Exception, e:
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
		time.sleep(5.)
sys.exit(0)
Esempio n. 4
0
				nextTest = min(nextTest, macList[thisMAC]["lastTesttt"] + (macList[thisMAC]["iPhoneRefreshUpSecs"]*0.90)   -tt )
			else:
				nextTest = min(nextTest, macList[thisMAC]["lastTesttt"] + macList[thisMAC]["iPhoneRefreshDownSecs"] -tt - macList[thisMAC]["quickTest"] )

			if True:
				nT= max(int(nextTest),1)
				fTest = nextTest / nT
				#print "fTest",thisMAC, fTest
				for ii in range(nT):
					tt=time.time()
					if fTest > 0:
						time.sleep(fTest)  # print "time to sleep "+datetime.datetime.now().strftime("%M:%S"), macList[thisMAC]["up"], macList[thisMAC]["quickTest"], nextTest
					#if thisMAC == "54:9F:13:3F:95:26":
						#print thisMAC, onlyThisMAC, nowP, tt, nowTest, tt-nowTest
					if not nowP and tt-nowTest > 20.:
						quick = U.checkNowFile(sensor)				  
						if quick:
							for ml in macList :
								if onlyThisMAC != "" and onlyThisMAC != ml: continue
								macList[ml]["lastData"]	   = {"signal":-999,"txPower":-999}
								macList[ml]["lastTesttt"]  = 0.
								#macList[ml]["lastMsgtt"]  = 0.
								macList[ml]["retryIfUPtemp"] = macList[ml]["retryIfUP"]
								macList[ml]["retryIfUP"] = False
								macList[ml]["up"]		 = False
							nowTest = tt
							nowP	= True
							#print " received BLEconnect now,", thisMAC,onlyThisMAC, "setting nowTest",	 nowTest
							break

					if nowP and tt - nowTest > 5 and tt - nowTest < 10.: