예제 #1
0
def getValues(devId, nMeasurements=5):
    global sensor, sensors, mhz19sensor, badSensor
    global startTime, CO2offset, CO2normal, sensitivity

    try:
        ret = "badSensor"
        if mhz19sensor[devId] == "":
            badSensor += 1
            return "badSensor"
        nnn = max(2, nMeasurements)
        raw = 0
        nMeas = 0.
        addIfBad = 2
        ii = 0
        rawData = []
        while ii < nnn:
            ii += 1
            mhz19sensor[devId].measure()
            co2 = mhz19sensor[devId].co2
            try:
                rawData = mhz19sensor[devId].raw
            except:
                pass
            U.toLog(1, " co2 raw: %d" % co2)
            if co2 == -1:
                ii -= addIfBad  # onetime only
                addIfBad = 0
                U.toLog(-1, u"bad data read ")

                continue
            raw += co2
            nMeas += 1.
            if ii != nnn - 1: time.sleep(2)
            if ii % 5 == 0: U.echoLastAlive(G.program)

        if raw == 0:
            needRestart = True
            badSensor += 1
            if badSensor > 3: ret = "badSensor"
            return ret

        raw /= nMeas

        CO2 = raw + CO2offset[devId]
        #print "raw, CO2, CO2offset, CO2normal", raw, CO2, CO2offset[devId], CO2normal[devId]
        ret = {
            "CO2": (round(CO2, 1)),
            "CO2offset": (round(CO2offset[devId], 1)),
            "CO2calibration": (round(CO2normal[devId], 1)),
            "rawData": (rawData),
            "raw": (round(raw, 1))
        }
        U.toLog(1, unicode(ret))
        badSensor = 0
    except Exception, e:
        U.toLog(
            -1,
            u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
        badSensor += 1
        if badSensor > 3: ret = "badSensor"
예제 #2
0
파일: mhzSERIAL.py 프로젝트: kw123/piBeacon
def getValues(devId,nMeasurements=5):
	global sensor, sensors,	 mhz19sensor, badSensor
	global startTime, CO2offset, CO2normal, sensitivity

	try:
		ret ="badSensor"
		if mhz19sensor[devId] =="": 
			badSensor +=1
			return "badSensor"
		nnn		 = max(2,nMeasurements)
		raw		 = 0
		nMeas	 = 0.
		addIfBad = 2
		ii		 = 0
		rawData	 =[]
		while ii < nnn:
			ii+=1
			mhz19sensor[devId].measure()
			co2 =  mhz19sensor[devId].co2
			try: rawData =	mhz19sensor[devId].raw
			except: pass
			U.toLog(1, " co2 raw: %d" %co2 )
			if co2 ==-1: 
				ii -= addIfBad	# onetime only 
				addIfBad = 0
				U.toLog(-1, u"bad data read ")

				continue
			raw += co2
			nMeas +=1.
			if ii != nnn-1: time.sleep(2)
			if ii%5 ==0: U.echoLastAlive(G.program)

		if raw ==0:
			needRestart =True
			badSensor+=1
			if badSensor >3: ret = "badSensor"
			return ret
		
		raw /= nMeas 
			
		CO2 = raw + CO2offset[devId]
		#print "raw, CO2, CO2offset, CO2normal", raw, CO2, CO2offset[devId], CO2normal[devId]
		ret	 = {"CO2":			 ( round(CO2,1)			   )
			   ,"CO2offset":	 ( round(CO2offset[devId],1)	  )
			   ,"CO2calibration":( round(CO2normal[devId],1) ) 
			   ,"rawData":		 ( rawData				   ) 
			   ,"raw":			 ( round(raw,1)			   ) }
		U.toLog(1, unicode(ret)) 
		badSensor = 0
	except	Exception, e:
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
		badSensor+=1
		if badSensor >3: ret = "badSensor"
예제 #3
0
            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)
            quick = U.checkNowFile(G.program)
            if tt - lastRead > 5:
                lastRead = tt
예제 #4
0
파일: bno055.py 프로젝트: kw123/piBeacon
BNO055sensor				={}
myPID		= str(os.getpid())
U.killOldPgm(myPID,G.program+".py")# kill old instances of myself if they are still running


if U.getIPNumber() > 0:
	time.sleep(10)
	exit()

readParams()

time.sleep(1)

lastRead = time.time()

U.echoLastAlive(G.program)



lastValueDefault	= {"EULER":{"heading":0,"roll":0,"pitch":0},"MAG":{"x":0,"y":0,"z":0},"GRAV":{"x":0,"y":0,"z":0},"ACC":{"x":0,"y":0,"z":0},"LIN":{"x":0,"y":0,"z":0}}
lastRead			= time.time()
G.lastAliveSend		= time.time() -1000
testDims			= ["GRAV","LIN"]
testCoords			= ["x","y","z"]
testForBadSensor	= "MAG"
lastValue			= {}
thresholdDefault	= 0.1
sumTest				={"dim":"GRAV","limits":[0,250.]}
singleTest			={"dim":"EULER","coord":"heading","limits":[-9999.,400.]}

startTime = time.time()