예제 #1
0
def readParams():
    global sensorList, sensors, sendToIndigoSecs, sensorRefreshSecs
    global output
    global tempUnits, pressureUnits, distanceUnits
    global oldRaw, lastRead

    rCode = False

    inp, inpRaw, lastRead2 = U.doRead(lastTimeStamp=lastRead)
    if inp == "": return rCode
    if lastRead2 == lastRead: return rCode
    lastRead = lastRead2
    if inpRaw == oldRaw: return
    oldRaw = inpRaw

    oldSensor = sensorList
    sensorList = []
    sensorsOld = copy.copy(sensors)
    outputOld = unicode(output)

    U.getGlobalParams(inp)
    if "debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPISENSOR"])
    if "output" in inp: output = (inp["output"])
    if "sensors" in inp: sensors = (inp["sensors"])
    if "sensorRefreshSecs" in inp:
        sensorRefreshSecs = float(inp["sensorRefreshSecs"])

    sensorList = ""
    for sensor in sensors:
        sensorList += sensor.split("-")[0] + ","

    if sensorList.find("myprogram") == -1:
        exit()

    return rCode
예제 #2
0
파일: mag3110.py 프로젝트: kw123/piBeacon
def readParams():
	global sensors, sensor
	global rawOld
	global theSENSORdict
	global oldRaw, lastRead
	try:

		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return
		if lastRead2 == lastRead: return
		lastRead   = lastRead2
		if inpRaw == oldRaw: return
		oldRaw	   = inpRaw

		U.getGlobalParams(inp)
		if "sensors"			in inp:	 sensors =				 (inp["sensors"])
		if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPISENSOR"])
 
		if sensor not in sensors:
			U.toLog(-1, G.program+" is not in parameters = not enabled, stopping "+G.program+".py" )
			exit()
				
		for devId in sensors[sensor]:
			U.getMAGReadParameters(sensors[sensor][devId],devId)
			if devId not in theSENSORdict:
				startTheSensor(devId, G.i2cAddress, G.offsetTemp[devId], G.magOffset[devId], G.magDivider[devId], G.declination[devId], G.magResolution[devId],G.enableCalibration[devId])
			U.setMAGParams(theSENSORdict[devId],magOffset=G.magOffset[devId], magDivider=G.magDivider[devId],enableCalibration=G.enableCalibration[devId], declination=G.declination[devId], offsetTemp=G.offsetTemp[devId])
			 
		theSENSORdict = U.cleanUpSensorlist( sensors[sensor], theSENSORdict)	   

	except	Exception, e:
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #3
0
def readParams():
		global output
		global INPgpioType,OUTPUTlastvalue
		global oldRaw, lastRead


		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return
		if lastRead2 == lastRead: return
		lastRead   = lastRead2
		if inpRaw == oldRaw: return
		oldRaw	   = inpRaw
		oldoutput		  = output

		U.getGlobalParams(inp)
		if "output"			in inp : output =				(inp["output"])
		if "debugRPI"		in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPIOUTPUT"])


		restart = False
			
		if "OUTPUTgpio-1-ONoff" not in output:
			print "OUTPUTgpio-1-ONoff not in output" 
			exit()
				
		if restart:
			U.restartMyself(reason="new parameters")
예제 #4
0
def readParams():
	global sensors, sensor 
	global theSENSORdict 
	global oldRaw, lastRead
	try:

		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return
		if lastRead2 == lastRead: return
		lastRead   = lastRead2
		if inpRaw == oldRaw: return
		oldRaw	   = inpRaw

		U.getGlobalParams(inp)
		if "sensors"			in inp:	 sensors =				 (inp["sensors"])
		if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPISENSOR"])
 
		if sensor not in sensors:
			U.toLog(-1, G.program+" is not in parameters = not enabled, stopping "+G.program+".py" )
			exit()
				
		for devId in sensors[sensor]:
			U.getMAGReadParameters(sensors[sensor][devId],devId)
			if devId not in theSENSORdict:
				startTheSensor(devId, G.i2cAddress,	 G.magResolution[devId],  G.declination[devId],	 G.magOffset[devId],  G.magDivider[devId],	G.enableCalibration[devId])
			U.setMAGParams(theSENSORdict[devId],magOffset= G.magOffset[devId], magDivider= G.magDivider[devId], declination= G.declination[devId])
		 
		theSENSORdict = U.cleanUpSensorlist( sensors[sensor], theSENSORdict)	   

	except	Exception, e:
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #5
0
def readParams():
    global output
    global INPgpioType, OUTPUTlastvalue
    global oldRaw, lastRead

    inp, inpRaw, lastRead2 = U.doRead(lastTimeStamp=lastRead)
    if inp == "": return
    if lastRead2 == lastRead: return
    lastRead = lastRead2
    if inpRaw == oldRaw: return
    oldRaw = inpRaw
    oldoutput = output

    U.getGlobalParams(inp)
    if "output" in inp: output = (inp["output"])
    if "debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPIOUTPUT"])

    restart = False

    if "OUTPUTgpio-1-ONoff" not in output:
        print "OUTPUTgpio-1-ONoff not in output"
        exit()

    if restart:
        U.restartMyself(reason="new parameters")
예제 #6
0
def readParams():
    global sList, sensors
    global INPgpioType, INPUTcount, INPUTlastvalue
    global oldRaw, lastRead

    INPUTcount = U.checkresetCount(INPUTcount)

    inp, inpRaw, lastRead2 = U.doRead(lastTimeStamp=lastRead)
    if inp == "": return
    if lastRead2 == lastRead: return
    lastRead = lastRead2
    if inpRaw == oldRaw: return
    oldRaw = inpRaw

    oldSensors = sensors

    U.getGlobalParams(inp)
    if "sensors" in inp: sensors = (inp["sensors"])
    if "debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPISENSOR"])

    restart = False
    sList = ""
    for sensor in sensors:
        sList += sensor

    if "INPUTgpio" not in sList:
        print "INPUTgpio not in sensorlist"
        exit()
    else:
        if oldSensors != {}:  # this is {}  at startup.. dont do anything
            for sensor in sensors:
                if "INPUTgpio" in sensor.split("-")[0]:
                    if sensor not in oldSensors:
                        restart = True
                        U.toLog(
                            -1, "new sensor def:" +
                            unicode(sensors[sensor][devId]["INPUTS"]))
                        break
                    for devId in sensors[sensor]:
                        if devId not in oldSensors[sensor]:
                            restart = True
                            U.toLog(
                                -1, "new sensor def:" +
                                unicode(sensors[sensor][devId]["INPUTS"]))
                            break
                        if sensors[sensor][devId]["INPUTS"] != oldSensors[
                                sensor][devId]["INPUTS"]:
                            restart = True
                            U.toLog(
                                -1, "new sensor def:" +
                                unicode(sensors[sensor][devId]["INPUTS"]))
                            U.toLog(
                                -1, "old sensor def:" +
                                unicode(oldSensors[sensor][devId]["INPUTS"]))
                            break
                if restart: break

    if restart:
        U.restartMyself(reason="new parameters")
예제 #7
0
def readParams():
	global sensors, sensor
	global BNO055sensor, resetPin
	global oldRaw, lastRead

	try:

		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return
		if lastRead2 == lastRead: return
		lastRead   = lastRead2
		if inpRaw == oldRaw: return
		oldRaw	   = inpRaw



		externalSensor=False
		sensorsOld= copy.copy(sensors)

 
		
		U.getGlobalParams(inp)
		if "sensors"			in inp:	 sensors =				 (inp["sensors"])
		if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPISENSOR"])
		
 
		if sensor not in sensors:
			U.toLog(-1, "BNO055 is not in parameters = not enabled, stopping ina219.py" )
			exit()
			
				
		for devId in sensors[sensor]:
			U.getMAGReadParameters(sensors[sensor][devId],devId)


			try:
				if "resetPin" in sensors[sensor][devId]: 
					resetPin= int(sensors[sensor][devId]["resetPin"])
			except:
				resetPin = -1
				
			if devId not in BNO055sensor:
				startBNO(devId, G.i2cAddress)
				
		deldevID={}		   
		for devId in BNO055sensor:
			if devId not in sensors[sensor]:
				deldevID[devId]=1
		for dd in  deldevID:
			del BNO055sensor[dd]
		if len(BNO055sensor) ==0: 
			####exit()
			pass

	except	Exception, e:
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #8
0
def readParams():
	global execcommands, PWM
	inp,inpRaw = U.doRead()
	if inp == "": return
	try:
		if u"debugRPI"				in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPIOUTPUT"])
		if u"GPIOpwm"				in inp:	 PWM=				  int(inp["GPIOpwm"])
		U.getGlobalParams(inp)
	except	Exception, e:
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #9
0
def readParams():
    global execcommands, PWM
    inp, inpRaw = U.doRead()
    if inp == "": return
    try:
        if u"debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPIOUTPUT"])
        if u"GPIOpwm" in inp: PWM = int(inp["GPIOpwm"])
        U.getGlobalParams(inp)
    except Exception, e:
        U.toLog(
            -1,
            u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #10
0
파일: INPUTgpio.py 프로젝트: kw123/piBeacon
def readParams():
		global sList,sensors
		global INPgpioType,INPUTcount,INPUTlastvalue
		global oldRaw, lastRead

		INPUTcount= U.checkresetCount(INPUTcount)


		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return
		if lastRead2 == lastRead: return
		lastRead   = lastRead2
		if inpRaw == oldRaw: return
		oldRaw	   = inpRaw

		oldSensors		  = sensors

		U.getGlobalParams(inp)
		if "sensors"			in inp : sensors =				(inp["sensors"])
		if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPISENSOR"])

		restart = False
		sList = ""
		for sensor in sensors:
			sList+=sensor
			
		if "INPUTgpio" not in sList:
			print "INPUTgpio not in sensorlist" 
			exit()
		else:
			if oldSensors != {}: # this is {}  at startup.. dont do anything 
				for sensor in sensors:
					if "INPUTgpio" in sensor.split("-")[0]:
						if sensor not in oldSensors:
							restart=True
							U.toLog(-1, "new sensor def:" + unicode( sensors[sensor][devId]["INPUTS"])	)
							break
						for devId in sensors[sensor]:
							if devId  not in oldSensors[sensor]:
								restart=True
								U.toLog(-1, "new sensor def:" + unicode( sensors[sensor][devId]["INPUTS"])	)
								break
							if sensors[sensor][devId]["INPUTS"] != oldSensors[sensor][devId]["INPUTS"]:
								restart=True
								U.toLog(-1, "new sensor def:" + unicode( sensors[sensor][devId]["INPUTS"])	 )
								U.toLog(-1, "old sensor def:" + unicode(oldSensors[sensor][devId]["INPUTS"]) )
								break
					if restart: break
				
		if restart:
			U.restartMyself(reason="new parameters")
예제 #11
0
파일: BLEsensor.py 프로젝트: kw123/piBeacon
def readParams(init):
	global BLEsensorMACs
	global oldRaw,	lastRead, sensor
	if init:
		G.debug			  = 2
		G.ipOfServer	  =""
		G.passwordOfServer=""
		G.userIdOfServer  =""
		G.myPiNumber	  ="0"

	inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
	if inp == "":				return False
	if lastRead2 == lastRead:	return False
	lastRead   = lastRead2
	if inpRaw == oldRaw:		return False
	oldRaw	   = inpRaw

	try:
		U.getGlobalParams(inp)

		if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPIBEACON"])
		if "rebootSeconds"		in inp:	 rebootSeconds=		  int(inp["rebootSeconds"])
		if "enableRebootCheck"	in inp:	 enableRebootCheck=		 (inp["enableRebootCheck"])
		if "sendAfterSeconds"	in inp:	 sendAfterSeconds=	  int(inp["sendAfterSeconds"])

		BLEsensorMACs = {}
		sensor		  = "BLEsensor"
		if "sensors"			 in inp: 
			sensors =				 (inp["sensors"])
			if sensor in sensors:
				for devId in sensors[sensor]:
					sensD	= sensors[sensor][devId]
					mac		= sensD["mac"]
					BLEsensorMACs[mac]={}
					BLEsensorMACs[mac]["type"]						 = sensD["type"]
					BLEsensorMACs[mac]["devId"]						 = devId
					try:	BLEsensorMACs[mac]["offsetTemp"]		 = float(sensD["offsetTemp"])
					except: BLEsensorMACs[mac]["offsetTemp"]		 = 0.
					try:	BLEsensorMACs[mac]["multiplyTemp"]		 = float(sensD["multiplyTemp"])
					except: BLEsensorMACs[mac]["multiplyTemp"]		 = 1.
					try:	BLEsensorMACs[mac]["offsetWind"]		 = float(sensD["offsetWind"])
					except: BLEsensorMACs[mac]["offsetWind"]		 = 0.
					try:	BLEsensorMACs[mac]["multiplyWind"]		 = float(sensD["multiplyWind"])
					except: BLEsensorMACs[mac]["multiplyWind"]		 = 1.
					try:	BLEsensorMACs[mac]["updateIndigoTiming"] = float(sensD["updateIndigoTiming"])
					except: BLEsensorMACs[mac]["updateIndigoTiming"] = 0.
					BLEsensorMACs[mac]["lastUpdate"]				 = -1
		print "BLE sensors found: ",BLEsensorMACs

	except	Exception, e:
		U.toLog(-1,u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #12
0
def readParams():
    global sensors, sensor
    global rawOld
    global theSENSORdict, resetPin
    global oldRaw, lastRead
    try:

        inp, inpRaw, lastRead2 = U.doRead(lastTimeStamp=lastRead)
        if inp == "": return
        if lastRead2 == lastRead: return
        lastRead = lastRead2
        if inpRaw == oldRaw: return
        oldRaw = inpRaw
        externalSensor = False
        sensorsOld = copy.copy(sensors)

        if "sensors" in inp: sensors = (inp["sensors"])
        if "debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPISENSOR"])

        U.getGlobalParams(inp)

        if sensor not in sensors:
            U.toLog(
                -1, G.program +
                "is not in parameters = not enabled, stopping " + G.program)
            exit()

        for devId in sensors[sensor]:
            changed = U.getMAGReadParameters(sensors[sensor][devId], devId)
            if changed.find("accelerationGain") > -1 or changed.find(
                    "magGain") > -1:
                U.restartMyself(reason="new gain seetungs require restart ",
                                doPrint=False)

            if devId not in theSENSORdict:
                startSENSOR(devId, G.i2cAddress)

        deldevID = {}
        for devId in theSENSORdict:
            if devId not in sensors[sensor]:
                deldevID[devId] = 1
        for dd in deldevID:
            del theSENSORdict[dd]
        if len(theSENSORdict) == 0:
            ####exit()
            pass

    except Exception, e:
        U.toLog(
            -1,
            u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #13
0
def readParams():
	global sensorList, sensors,	 sensor,  sensorRefreshSecs, displayEnable
	global output, sensorActive, timing
	global oldRaw, lastRead
	try:

		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return
		if lastRead2 == lastRead: return
		lastRead   = lastRead2
		if inpRaw == oldRaw: return
		oldRaw	   = inpRaw

		externalSensor=False
		sensorList=[]
		sensorsOld= copy.copy(sensors)

		U.getGlobalParams(inp)
		  
		  
		if "sensors"			 in inp:  sensors =				  (inp["sensors"])
		if "debugRPI"			 in inp:  G.debug=			   int(inp["debugRPI"]["debugRPISENSOR"])
		if "output"				 in inp:  output=				  (inp["output"])
		if "tempUnits"			 in inp:  tempUnits=			  (inp["tempUnits"])

		if sensor not in sensors:
			U.toLog(-1, G.program+" is not in parameters = not enabled, stopping "+G.program )
			exit()
			
		sensorChanged = doWeNeedToStartSensor(sensors,sensorsOld,sensor)
			
		if sensorChanged == -1:
			U.toLog(-1, "==== stop	"+G.program+ " sensorChanged==-1 =====")
			exit()

		U.getGlobalParams(inp)



		for devId in sensors[sensor]:
			U.getMAGReadParameters(sensors[sensor][devId],devId)

		if sensorChanged != 0: # something has changed
			if os.path.isfile(G.homeDir+"temp/"+sensor+".dat"):
				os.remove(G.homeDir+"temp/"+sensor+".dat")
				
			

	except	Exception, e:
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #14
0
파일: lsm303.py 프로젝트: kw123/piBeacon
def readParams():
	global sensors, sensor
	global rawOld
	global theSENSORdict, resetPin
	global oldRaw, lastRead
	try:

		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return
		if lastRead2 == lastRead: return
		lastRead   = lastRead2
		if inpRaw == oldRaw: return
		oldRaw	   = inpRaw
		externalSensor=False
		sensorsOld= copy.copy(sensors)

		if "sensors"			in inp:	 sensors =				 (inp["sensors"])
		if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPISENSOR"])

		U.getGlobalParams(inp)
		
		
 
		if sensor not in sensors:
			U.toLog(-1, G.program+"is not in parameters = not enabled, stopping "+G.program )
			exit()
			
				
		for devId in sensors[sensor]:
			changed=  U.getMAGReadParameters(sensors[sensor][devId],devId) 
			if	changed.find("accelerationGain") >-1  or changed.find("magGain") >-1: 
				U.restartMyself(reason="new gain seetungs require restart ",doPrint=False)

				
			if devId not in theSENSORdict:
				startSENSOR(devId, G.i2cAddress)
				
		deldevID={}		   
		for devId in theSENSORdict:
			if devId not in sensors[sensor]:
				deldevID[devId]=1
		for dd in  deldevID:
			del theSENSORdict[dd]
		if len(theSENSORdict) ==0: 
			####exit()
			pass

	except	Exception, e:
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #15
0
def readParams():
    global sensors, sensor
    global threshold, theSENSORdict
    global oldRaw, lastRead
    try:

        inp, inpRaw, lastRead2 = U.doRead(lastTimeStamp=lastRead)
        if inp == "": return
        if lastRead2 == lastRead: return
        lastRead = lastRead2
        if inpRaw == oldRaw: return
        oldRaw = inpRaw

        externalSensor = False
        sensorsOld = copy.copy(sensors)
        U.getGlobalParams(inp)

        if "sensors" in inp: sensors = (inp["sensors"])
        if "debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPISENSOR"])

        if sensor not in sensors:
            U.toLog(
                -1, G.program +
                " is not in parameters = not enabled, stopping " + G.program)
            exit()

        for devId in sensors[sensor]:
            U.getMAGReadParameters(sensors[sensor][devId], devId)

            if devId not in theSENSORdict:
                U.toLog(
                    -1, "==== Start " + G.program + " ===== @ i2c= " +
                    unicode(G.i2cAddress))
                theSENSORdict[devId] = THESENSORCLASS(i2cAddress=G.i2cAddress)

        deldevID = {}
        for devId in theSENSORdict:
            if devId not in sensors[sensor]:
                deldevID[devId] = 1
        for dd in deldevID:
            del theSENSORdict[dd]
        if len(theSENSORdict) == 0:
            ####exit()
            pass

    except Exception, e:
        U.toLog(
            -1,
            u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #16
0
def readParams():
	global	output, useLocalTime, myPiNumber, inp
	inp,inpRaw = U.doRead()
	if inp == "": return
	try:
		f=open(G.homeDir+"parameters","r")
		try:	inp =json.loads(f.read())
		except: return
		f.close()
		U.getGlobalParams(inp)
		if u"debugRPI"			in inp:	 G.debug=			int(inp["debugRPI"]["debugRPIOUTPUT"])
		if u"output"			in inp:	 output=				inp["output"]

	except	Exception, e:
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #17
0
def readParams():
    global frequency, defFreq, mute, mono, highCut, noiseCancel, bandLimit, DTCon, PLLREF, XTAL, i2cAddress, HLSI, devIdFound

    global fastFreq, fastMute, fastMono, inp
    global oldRaw, lastRead
    try:

        inp, inpRaw, lastRead2 = U.doRead(lastTimeStamp=lastRead)
        if inp == "": return
        if lastRead2 == lastRead: return
        lastRead = lastRead2
        if inpRaw == oldRaw: return
        oldRaw = inpRaw

        U.getGlobalParams(inp)
        if u"debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPIOUTPUT"])

        device = "setTEA5767"
        if device in inp["output"]:
            for devId in inp["output"][device]:
                input = inp["output"][device][devId][0]
                if u"mute" in input: mute = int(input["mute"])
                if u"mono" in input: mono = int(input["mono"])
                if u"highCut" in input: highCut = int(input["highCut"])
                if u"noiseCancel" in input:
                    noiseCancel = int(input["noiseCancel"])
                if u"bandLimit" in input: bandLimit = int(input["bandLimit"])
                if u"DTCon" in input: DTCon = int(input["DTCon"])
                if u"PLLREF" in input: PLLREF = int(input["PLLREF"])
                if u"XTAL" in input: XTAL = int(input["XTAL"])
                if u"defFreq" in input:
                    defFreq = float(input["defFreq"])
                    frequency = float(input["defFreq"])
                if u"HLSI" in input: HLSI = int(input["HLSI"])
                if u"i2cAddress" in input:
                    i2cAddress = int(input["i2cAddress"])
                devIdFound = devId
                break

        else:
            U.toLog(
                -1, u"stopping FM radio, no device defined in parameters file")
            exit()
    except Exception, e:
        U.toLog(
            -1,
            u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #18
0
def readParams():
    global sensorList, sensors, sendToIndigoSecs, enableTXpinsAsGpio, enableSPIpinsAsGpio, sensorRefreshSecs
    global output
    global tempUnits, pressureUnits, distanceUnits
    global oldRaw, lastRead
    global clockLightSensor
    global addNewOneWireSensors

    rCode = False

    inp, inpRaw, lastRead2 = U.doRead(lastTimeStamp=lastRead)
    if inp == "": return rCode
    if lastRead2 == lastRead: return rCode
    lastRead = lastRead2
    if inpRaw == oldRaw: return
    oldRaw = inpRaw

    oldSensor = sensorList
    sensorsOld = copy.copy(sensors)
    outputOld = unicode(output)

    U.getGlobalParams(inp)
    if "debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPISENSOR"])
    if "enableSPIpinsAsGpio" in inp:
        enableSPIpinsAsGpio = (inp["enableSPIpinsAsGpio"])
    if "enableTXpinsAsGpio" in inp:
        enableTXpinsAsGpio = (inp["enableTXpinsAsGpio"])
    if "output" in inp: output = (inp["output"])
    if "tempUnits" in inp: tempUnits = (inp["tempUnits"])
    if "pressureUnits" in inp: pressureUnits = (inp["pressureUnits"])
    if "distanceUnits" in inp: distanceUnits = (inp["distanceUnits"])
    if "sensors" in inp: sensors = (inp["sensors"])
    if "sensorRefreshSecs" in inp:
        sensorRefreshSecs = float(inp["sensorRefreshSecs"])
    if "addNewOneWireSensors" in inp:
        addNewOneWireSensors = (inp["addNewOneWireSensors"])

    sensorList = ""
    for sensor in sensors:
        sensorList += sensor.split("-")[0] + ","
    if sensorList.find("Wire18B20") == -1:
        exit()

    return
예제 #19
0
파일: l3g4200.py 프로젝트: kw123/piBeacon
def readParams():
	global sensors, sensor
	global threshold, theSENSORdict
	global oldRaw, lastRead
	try:

		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return
		if lastRead2 == lastRead: return
		lastRead   = lastRead2
		if inpRaw == oldRaw: return
		oldRaw	   = inpRaw

		externalSensor=False
		sensorsOld= copy.copy(sensors)
		U.getGlobalParams(inp)
		  
		if "sensors"			in inp:	 sensors =				 (inp["sensors"])
		if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPISENSOR"])
		
 
		if sensor not in sensors:
			U.toLog(-1, G.program+" is not in parameters = not enabled, stopping "+G.program )
			exit()

		for devId in sensors[sensor]:
			U.getMAGReadParameters(sensors[sensor][devId],devId)

			if devId not in theSENSORdict:
				U.toLog(-1,"==== Start "+G.program+" ===== @ i2c= " +unicode(G.i2cAddress))
				theSENSORdict[devId] = THESENSORCLASS(i2cAddress=G.i2cAddress)
				
		deldevID={}		   
		for devId in theSENSORdict:
			if devId not in sensors[sensor]:
				deldevID[devId]=1
		for dd in  deldevID:
			del theSENSORdict[dd]
		if len(theSENSORdict) ==0: 
			####exit()
			pass

	except	Exception, e:
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #20
0
def readParams():
    global output, useLocalTime, myPiNumber, inp
    inp, inpRaw = U.doRead()
    if inp == "": return
    try:
        f = open(G.homeDir + "parameters", "r")
        try:
            inp = json.loads(f.read())
        except:
            return
        f.close()
        U.getGlobalParams(inp)
        if u"debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPIOUTPUT"])
        if u"output" in inp: output = inp["output"]

    except Exception, e:
        U.toLog(
            -1,
            u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #21
0
def readParams():
    global frequency, defFreq, mute, mono, highCut, noiseCancel, bandLimit, DTCon, PLLREF, XTAL,i2cAddress, HLSI,devIdFound

    global fastFreq, fastMute,fastMono, inp
    global oldRaw, lastRead
    try:

        inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
        if inp == "": return 
        if lastRead2 == lastRead: return 
        lastRead   = lastRead2
        if inpRaw == oldRaw: return 
        oldRaw     = inpRaw

        U.getGlobalParams(inp)
        if u"debugRPI"          in inp:  G.debug=              int(inp["debugRPI"]["debugRPIOUTPUT"])


        device = "setTEA5767"
        if device in inp["output"]:
            for devId in inp["output"][device]:
                input= inp["output"][device][devId][0]
                if u"mute"              in input:  mute=                 int(input["mute"])
                if u"mono"              in input:  mono=                 int(input["mono"])
                if u"highCut"           in input:  highCut=              int(input["highCut"])
                if u"noiseCancel"       in input:  noiseCancel=          int(input["noiseCancel"])
                if u"bandLimit"         in input:  bandLimit=            int(input["bandLimit"])
                if u"DTCon"             in input:  DTCon=                int(input["DTCon"])
                if u"PLLREF"            in input:  PLLREF=               int(input["PLLREF"])
                if u"XTAL"              in input:  XTAL=                 int(input["XTAL"])
                if u"defFreq"           in input:  
                                                   defFreq=            float(input["defFreq"])
                                                   frequency=          float(input["defFreq"])
                if u"HLSI"              in input:  HLSI=                 int(input["HLSI"])
                if u"i2cAddress"        in input:  i2cAddress=           int(input["i2cAddress"])
                devIdFound = devId
                break

        else:
            U.toLog(-1, u"stopping FM radio, no device defined in parameters file")
            exit()
    except  Exception, e:
        U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #22
0
파일: Wire18B20.py 프로젝트: kw123/piBeacon
def readParams():
        global sensorList, sensors, sendToIndigoSecs,enableTXpinsAsGpio,enableSPIpinsAsGpio, sensorRefreshSecs
        global output
        global tempUnits, pressureUnits, distanceUnits
        global oldRaw, lastRead
        global clockLightSensor
        global addNewOneWireSensors

        rCode= False

        inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
        if inp == "": return rCode
        if lastRead2 == lastRead: return rCode
        lastRead  = lastRead2
        if inpRaw == oldRaw: return 
        oldRaw     = inpRaw

        oldSensor  = sensorList
        sensorsOld = copy.copy(sensors)
        outputOld  = unicode(output)


        U.getGlobalParams(inp)
        if "debugRPI"             in inp:  G.debug=             int(inp["debugRPI"]["debugRPISENSOR"])
        if "enableSPIpinsAsGpio"  in inp: enableSPIpinsAsGpio=     (inp["enableSPIpinsAsGpio"])
        if "enableTXpinsAsGpio"   in inp: enableTXpinsAsGpio=      (inp["enableTXpinsAsGpio"])
        if "output"               in inp: output=                  (inp["output"])
        if "tempUnits"            in inp: tempUnits=               (inp["tempUnits"])
        if "pressureUnits"        in inp: pressureUnits=           (inp["pressureUnits"])
        if "distanceUnits"        in inp: distanceUnits=           (inp["distanceUnits"])
        if "sensors"              in inp: sensors =                (inp["sensors"])
        if "sensorRefreshSecs"    in inp: sensorRefreshSecs = float(inp["sensorRefreshSecs"])
        if "addNewOneWireSensors" in inp: addNewOneWireSensors =   (inp["addNewOneWireSensors"])


        sensorList=""
        for sensor in sensors:
            sensorList+=sensor.split("-")[0]+","
        if sensorList.find("Wire18B20") ==-1:
            exit()

        return
예제 #23
0
def readParams():
        global debug, sensorList,freeParameter,sensorRefreshSecs, sensors

        sensorList  = "0"
        oldfreeParameter = copy.copy(freeParameter)
        inp,inRaw = U.doRead()

        U.getGlobalParams(inp)
        if u"debugRPI"          in inp:  G.debug=                    int(inp["debugRPI"]["debugRPImystuff"])
        if "sensors"            in inp:  sensors =                   (inp["sensors"])

        if G.program not in sensors: 
            exit()
        sensor = sensors[G.program]
        for id in sensor:
            if "freeParameter"  in sensor[id]:  freeParameter[id] =             sensor[id]["freeParameter"]

        # check if anything new
        if id not in oldfreeParameter or freeParameter[id] != oldfreeParameter[id]:
            startMySensors(freeParameter[id])
예제 #24
0
def readParams():
    global debug, sensorList, freeParameter, sensorRefreshSecs, sensors

    sensorList = "0"
    oldfreeParameter = copy.copy(freeParameter)
    inp, inRaw = U.doRead()

    U.getGlobalParams(inp)
    if u"debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPImystuff"])
    if "sensors" in inp: sensors = (inp["sensors"])

    if G.program not in sensors:
        exit()
    sensor = sensors[G.program]
    for id in sensor:
        if "freeParameter" in sensor[id]:
            freeParameter[id] = sensor[id]["freeParameter"]

    # check if anything new
    if id not in oldfreeParameter or freeParameter[id] != oldfreeParameter[id]:
        startMySensors(freeParameter[id])
예제 #25
0
def readParams():
    global debug, sensorList, launchCommand, launchCheck, sensorRefreshSecs, sensors, minSendDelta

    sensorList = "0"
    oldlaunchCommand = copy.copy(launchCommand)
    inp, inRaw = U.doRead()

    U.getGlobalParams(inp)
    if u"debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPImystuff"])
    if "sensors" in inp: sensors = (inp["sensors"])

    if G.program not in sensors:
        exit()
    sensor = sensors[G.program]
    for id in sensor:
        if "launchCommand" in sensor[id]:
            launchCommand[id] = sensor[id]["launchCommand"]
        if "launchCheck" in sensor[id]:
            launchCheck[id] = sensor[id]["launchCheck"]
        try:
            xx = sensors[sensor][devId]["sensorRefreshSecs"].split("#")
            sensorRefreshSecs = float(xx[0])
        except:
            sensorRefreshSecs = 100

        try:
            if "minSendDelta" in sensors[sensor][devId]:
                minSendDelta = float(
                    sensors[sensor][devId]["minSendDelta"]) / 100.
        except:
            minSendDelta = 5.

    # check if anything new
    if id not in oldlaunchCommand or launchCommand[id] != oldlaunchCommand[id]:
        startSensors(launchCommand[id])

    if id in oldlaunchCommand and id not in launchCommand:
        stopSensor(launchCommand[id])
예제 #26
0
파일: myprogram.py 프로젝트: kw123/piBeacon
def readParams():
        global sensorList, sensors, sendToIndigoSecs, sensorRefreshSecs
        global output
        global tempUnits, pressureUnits, distanceUnits
        global oldRaw, lastRead

        rCode= False

        inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
        if inp == "": return rCode
        if lastRead2 == lastRead: return rCode
        lastRead  = lastRead2
        if inpRaw == oldRaw: return 
        oldRaw     = inpRaw

        oldSensor  = sensorList
        sensorList = []
        sensorsOld = copy.copy(sensors)
        outputOld  = unicode(output)


        U.getGlobalParams(inp)
        if "debugRPI"             in inp:  G.debug=             int(inp["debugRPI"]["debugRPISENSOR"])
        if "output"               in inp: output=                  (inp["output"])
        if "sensors"              in inp: sensors =                (inp["sensors"])
        if "sensorRefreshSecs"    in inp: sensorRefreshSecs = float(inp["sensorRefreshSecs"])


        sensorList=""
        for sensor in sensors:
            sensorList+=sensor.split("-")[0]+","

        if sensorList.find("myprogram") ==-1:
            exit()

        return rCode
예제 #27
0
파일: bme680.py 프로젝트: kw123/piBeacon
def readParams():
	global sensorList, sensors, logDir, sensor,	 sensorRefreshSecs, displayEnable
	global rawOld
	global deltaX, BME680, minSendDelta
	global oldRaw, lastRead
	global startTime, calibrateIfgt, setCalibration, firstValue
	try:



		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return
		if lastRead2 == lastRead: return
		lastRead   = lastRead2
		if inpRaw == oldRaw: return
		oldRaw	   = inpRaw
		
		externalSensor=False
		sensorList=[]
		sensorsOld= copy.copy(sensors)


		
		U.getGlobalParams(inp)
		  
		if "sensorList"			in inp:	 sensorList=			 (inp["sensorList"])
		if "sensors"			in inp:	 sensors =				 (inp["sensors"])
		if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPISENSOR"])
		
 
		if sensor not in sensors:
			U.toLog(-1, "BME680 is not in parameters = not enabled, stopping BME680.py" )
			exit()
			

		U.toLog(1, "BME680 reading new parameter file" )

		if sensorRefreshSecs == 91:
			try:
				xx	   = str(inp["sensorRefreshSecs"]).split("#")
				sensorRefreshSecs = float(xx[0]) 
			except:
				sensorRefreshSecs = 91	  
		deltaX={}
		restart = False
		for devId in sensors[sensor]:
			deltaX[devId]  = 0.1
			old = sensorRefreshSecs
			try:
				if "sensorRefreshSecs" in sensors[sensor][devId]:
					xx = sensors[sensor][devId]["sensorRefreshSecs"].split("#")
					sensorRefreshSecs = float(xx[0]) 
			except:
				sensorRefreshSecs = 91	  
			if old != sensorRefreshSecs: restart = True

			old = calibrateIfgt
			try:
				if "calibrateIfgt" in sensors[sensor][devId]:
					calibrateIfgt = float(sensors[sensor][devId]["calibrateIfgt"])
			except:
				calibrateIfgt = 110	   
			if old > 200 and calibrateIfgt < 200:  restart = True  # switch from static to dyname, need to recalobarte = restart sensor

			try:
				if calibrateIfgt == 8888888.:
					if "setCalibration" in sensors[sensor][devId]:
						setCalibration = float(sensors[sensor][devId]["setCalibration"])
					else:
						setCalibration = 0	  
						calibrateIfgt  = 110  
				elif calibrateIfgt <200: 
					setCalibration = 0	  
				elif calibrateIfgt == 9999999.:
					try:
						f = open(G.homeDir+"bme680.Calibration","r")
						setCalibration = json.loads(f.read())["resistance"]
						f.close()
					except: 
						calibrateIfgt = 110	 # fallback if nothing in file
			except:
				setCalibration = 0	  
				calibrateIfgt  = 110	
			
			try:
				if "i2cAddress" in sensors[sensor][devId]: 
					i2cAddress = int(sensors[sensor][devId]["i2cAddress"])
			except:
				i2cAddress = ""	   

			old = deltaX[devId]
			try:
				if "deltaX" in sensors[sensor][devId]: 
					deltaX[devId]= float(sensors[sensor][devId]["deltaX"])/100.
			except:
				deltaX[devId] = 0.1
			if old != deltaX[devId]: restart = True

			old = minSendDelta
			try:
				if "minSendDelta" in sensors[sensor][devId]: 
					minSendDelta= float(sensors[sensor][devId]["minSendDelta"])
			except:
				minSendDelta = 5.
			if old != minSendDelta: restart = True

				
			if devId not in BMEsensor or  restart:
				startSensor(devId, i2cAddress)
				if BMEsensor[devId] =="":
					return
			U.toLog(-1," new parameters read: i2cAddress:" +unicode(i2cAddress) +";	 minSendDelta:"+unicode(minSendDelta)+
					   ";  deltaX:"+unicode(deltaX[devId])+";  calibrateIfgt:"+unicode(calibrateIfgt)+
					   ";  setCalibration:"+unicode(setCalibration) +";	 sensorRefreshSecs:"+unicode(sensorRefreshSecs) )
				
		deldevID={}		   
		for devId in BMEsensor:
			if devId not in sensors[sensor]:
				deldevID[devId]=1
		for dd in  deldevID:
			del BMEsensor[dd]
		if len(BMEsensor) ==0: 
			####exit()
			pass



	except	Exception, e:
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
		print sensors[sensor]
예제 #28
0
def readParams():
	global sensor, output, inpRaw, inp, DEVID,useRTC
	global clockDict, devTypeLEDs, speed, speedOfChange, clockLightSet,setClock, clockMode, gpiopinSET, clockLightSensor, minLightNotOff
	global lastCl, timeZone, currTZ
	global oldRaw, lastRead
	global doReadParameters
	try:

		if not doReadParameters: return
		changed =0
		inpLast= inp
		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)

		if inp == "": 
			inp = inpLast
			return changed
			
		if lastRead2 == lastRead: return changed
		lastRead  = lastRead2
		if inpRaw == "error":
			U.checkParametersFile("parameters-DEFAULT-clock", force = True)
		if inpRaw == oldRaw: return changed
		oldRaw	   = inpRaw
		U.getGlobalParams(inp)
		 
		if "debugRPI"				in inp:	 G.debug=		  int(inp["debugRPI"]["debugRPIOUTPUT"])
		if "useRTC"					in inp:	 useRTC=			 (inp["useRTC"])
		if "output"					in inp:	 output=			 (inp["output"])
		if "minLightNotOff"			in inp:	 minLightNotOff=  int(inp["minLightNotOff"])
		#### G.debug = 2 
		if "neopixelClock" not in output:
			U.toLog(-1, "neopixel-clock	 is not in parameters = not enabled, stopping "+ G.program+".py" )
			exit()
		clockLightSensor =0
		if "clockLightSensor"			in inp: 
			try:	xx = float(inp["clockLightSensor"])
			except: xx = 0
			clockLightSensor =xx

		clock = output["neopixelClock"]
		for devId in  clock:
			DEVID = devId
			clockDict= clock[devId][0]
			clu= unicode(clockDict)
			if lastCl == clu: 
				return changed

			lastCl = clu
			if "devTypeLEDs"	 not in clockDict: continue
			#if clockDict		!= "start" and json.dumps(clockDict)  != json.dumps(cl["neoPixelClock"]):	return 1
			changed = 1
			if "devTypeLEDs"	 in clockDict: 
				if devTypeLEDs !="start" and devTypeLEDs != clockDict["devTypeLEDs"]:
					changed = 2	  
				devTypeLEDs		=  clockDict["devTypeLEDs"]
			else:
					changed = 3	  
			if "timeZone"			 in clockDict:	
				if timeZone !=			   (clockDict["timeZone"]):
					changed = max(2, changed)  
					timeZone =				   (clockDict["timeZone"])
					tznew  = int(timeZone.split(" ")[0])
					if tznew != currTZ:
						U.toLog(-1, u"changing timezone from "+str(currTZ)+"  "+timeZones[currTZ+12]+" to "+str(tznew)+"  "+timeZones[tznew+12])
						os.system("sudo cp /usr/share/zoneinfo/"+timeZones[tznew+12]+" /etc/localtime")
						currTZ = tznew

			clockDict["timeZone"] = str(currTZ)+" "+ timeZones[currTZ+12]
				
			if "speedOfChange"	 in clockDict: speedOfChange   =  clockDict["speedOfChange"]
			if "speed"			 in clockDict: speed		   =  clockDict["speed"]

			if "clockLightSet"	 in clockDict: 
				xx											   =  clockDict["clockLightSet"]
				if	xx != clockLightSet:
					changed	  = max(changed,1)
				clockLightSet = xx
			try:
				if "GPIOsetA"			 in clockDict: gpiopinSET["setA"]			 =	int(clockDict["GPIOsetA"])
				if "GPIOsetB"			 in clockDict: gpiopinSET["setB"]			 =	int(clockDict["GPIOsetB"])
				if "GPIOsetC"			 in clockDict: gpiopinSET["setC"]			 =	int(clockDict["GPIOsetC"])
				if "GPIOup"				 in clockDict: gpiopinSET["up"]				 =	int(clockDict["GPIOup"])
				if "GPIOdown"			 in clockDict: gpiopinSET["down"]			 =	int(clockDict["GPIOdown"])
			except:
				pass

			## print clockDict
			break
		if devTypeLEDs == "start":	   changed = 3	# = no data inout restart myself in some seconds
		if changed ==2 : saveParameters()
		return changed

	except	Exception, e:
		print  u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e)
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
		time.sleep(10)
		return 3
예제 #29
0
def readParams():
    global sensor, sensors
    global gpioIn, gpioSW1, gpioSW2, gpioSW5, gpioSWP, cyclePower, sensorMode
    global ON, off
    global oldRaw, lastRead
    global switchToLowerSensitive, switchToHigherSensitive, bucketSize, bucketSize0, sendMSGEverySecs
    global status
    try:
        restart = False

        inp, inpRaw, lastRead2 = U.doRead(lastTimeStamp=lastRead)
        if inp == "": return
        if lastRead2 == lastRead: return
        lastRead = lastRead2
        if inpRaw == oldRaw: return
        oldRaw = inpRaw

        oldSensors = sensors

        U.getGlobalParams(inp)
        if "sensors" in inp: sensors = (inp["sensors"])
        if "debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPISENSOR"])

        if sensor not in sensors:
            U.toLog(0,
                    "no " + G.program + " sensor defined, exiting",
                    doPrint=True)
            exit()

        sens = sensors[sensor]
        found = {
            str(ii): {
                "RISING": 0,
                "GPIOchanged": 0,
                "BOTH": 0
            }
            for ii in range(100)
        }
        for devId in sens:
            sss = sens[devId]
            if "gpioIn" not in sss: continue
            if "gpioSW5" not in sss: continue
            if "gpioSW2" not in sss: continue
            if "gpioSW1" not in sss: continue
            if "gpioSWP" not in sss: continue
            if "sensorMode" not in sss: continue

            cp = sss["cyclePower"] != "0"

            if gpioIn != -1 and gpioIn != int(sss["gpioIn"]):
                restart = True
                U.toLog(0,
                        "gpios channel changed, need to restart",
                        doPrint=True)
                U.restartMyself(param="", reason=" new gpioIn", doPrint=True)
                return

            cyclePower = True
            if gpioSWP != int(sss["gpioSWP"]):
                gpioSWP = int(sss["gpioSWP"])
                if gpioSWP > 0: GPIO.setup(gpioSWP, GPIO.OUT)
                powerOFF(calledFrom="read")
            if gpioSW1 != int(sss["gpioSW1"]):
                gpioSW1 = int(sss["gpioSW1"])
                if gpioSW1 > 0: GPIO.setup(gpioSW1, GPIO.OUT)
            if gpioSW2 != int(sss["gpioSW2"]):
                gpioSW2 = int(sss["gpioSW2"])
                if gpioSW2 > 0: GPIO.setup(gpioSW2, GPIO.OUT)
            if gpioSW5 != int(sss["gpioSW5"]):
                gpioSW5 = int(sss["gpioSW5"])
                if gpioSW5 > 0: GPIO.setup(gpioSW5, GPIO.OUT)
            switchToLowerSensitive[
                "checkIfIsRaining"] = 10  # int(sss["TimeSwitchSensitivityRainToMayBeRaining"])
            switchToLowerSensitive[
                "maybeRain"] = 10  # int(sss["TimeSwitchSensitivityMayBeRainingToHigh"])
            switchToLowerSensitive[
                "highSensitive"] = 10  # int(sss["TimeSwitchSensitivityHighToMed"])
            switchToLowerSensitive[
                "medSensitive"] = 10  # int(sss["TimeSwitchSensitivityMedToLow"])

            switchToHigherSensitive[
                "lowSensitive"] = 100  # int(sss["TimeSwitchSensitivityLowToMed"])
            switchToHigherSensitive[
                "medSensitive"] = 100  # int(sss["TimeSwitchSensitivityMedToHigh"])
            switchToHigherSensitive[
                "highSensitive"] = 100  # int(sss["TimeSwitchSensitivityHighToAnyRain"])
            try:
                rainScaleFactor = float(sss["rainScaleFactor"])
            except:
                rainScaleFactor = 1.

            if gpioIn != int(sss["gpioIn"]):
                gpioIn = int(sss["gpioIn"])
                GPIO.setup(gpioIn, GPIO.IN, pull_up_down=GPIO.PUD_UP)
                GPIO.add_event_detect(gpioIn,
                                      GPIO.FALLING,
                                      callback=GPIOchanged,
                                      bouncetime=100)
                if sss["sensorMode"] != "dynamic":
                    setModeTo("checkIfIsRaining", calledFrom="readParams1")

            if sensorMode != sss["sensorMode"]:
                if sss["sensorMode"] != "dynamic":
                    sendShortStatus(rainMsg["checkIfIsRaining"])
                    nextModeSwitchNotBefore = time.time() + 2
                setModeTo(sss["sensorMode"],
                          force=True,
                          calledFrom="readParams2")

            sensorMode = sss["sensorMode"]
            sendMSGEverySecs = float(sss["sendMSGEverySecs"])
            time.sleep(0.4)
            powerON(calledFrom="read")
            cyclePower = cp

            bucketSize = {}
            for kk in bucketSize0:
                bucketSize[kk] = bucketSize0[kk] * rainScaleFactor

    except Exception, e:
        U.toLog(-1,
                u"in Line '%s' has error='%s'" %
                (sys.exc_traceback.tb_lineno, e),
                doPrint=True)
예제 #30
0
def readParams(init):
    global BLEsensorMACs
    global oldRaw, lastRead, sensor
    if init:
        G.debug = 2
        G.ipOfServer = ""
        G.passwordOfServer = ""
        G.userIdOfServer = ""
        G.myPiNumber = "0"

    inp, inpRaw, lastRead2 = U.doRead(lastTimeStamp=lastRead)
    if inp == "": return False
    if lastRead2 == lastRead: return False
    lastRead = lastRead2
    if inpRaw == oldRaw: return False
    oldRaw = inpRaw

    try:
        U.getGlobalParams(inp)

        if "debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPIBEACON"])
        if "rebootSeconds" in inp: rebootSeconds = int(inp["rebootSeconds"])
        if "enableRebootCheck" in inp:
            enableRebootCheck = (inp["enableRebootCheck"])
        if "sendAfterSeconds" in inp:
            sendAfterSeconds = int(inp["sendAfterSeconds"])

        BLEsensorMACs = {}
        sensor = "BLEsensor"
        if "sensors" in inp:
            sensors = (inp["sensors"])
            if sensor in sensors:
                for devId in sensors[sensor]:
                    sensD = sensors[sensor][devId]
                    mac = sensD["mac"]
                    BLEsensorMACs[mac] = {}
                    BLEsensorMACs[mac]["type"] = sensD["type"]
                    BLEsensorMACs[mac]["devId"] = devId
                    try:
                        BLEsensorMACs[mac]["offsetTemp"] = float(
                            sensD["offsetTemp"])
                    except:
                        BLEsensorMACs[mac]["offsetTemp"] = 0.
                    try:
                        BLEsensorMACs[mac]["multiplyTemp"] = float(
                            sensD["multiplyTemp"])
                    except:
                        BLEsensorMACs[mac]["multiplyTemp"] = 1.
                    try:
                        BLEsensorMACs[mac]["offsetWind"] = float(
                            sensD["offsetWind"])
                    except:
                        BLEsensorMACs[mac]["offsetWind"] = 0.
                    try:
                        BLEsensorMACs[mac]["multiplyWind"] = float(
                            sensD["multiplyWind"])
                    except:
                        BLEsensorMACs[mac]["multiplyWind"] = 1.
                    try:
                        BLEsensorMACs[mac]["updateIndigoTiming"] = float(
                            sensD["updateIndigoTiming"])
                    except:
                        BLEsensorMACs[mac]["updateIndigoTiming"] = 0.
                    BLEsensorMACs[mac]["lastUpdate"] = -1
        print "BLE sensors found: ", BLEsensorMACs

    except Exception, e:
        U.toLog(
            -1,
            u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #31
0
파일: mhzSERIAL.py 프로젝트: kw123/piBeacon
def readParams():
	global sensorList, sensors, logDir, sensor,	 sensorRefreshSecs
	global rawOld,calibrationPin, amplification
	global deltaX, mhz19, minSendDelta
	global oldRaw, lastRead
	global startTime
	global CO2normal, CO2offset,sensitivity,timeaboveCalibrationMAX
	try:


		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return
		if lastRead2 == lastRead: return
		lastRead   = lastRead2
		if inpRaw == oldRaw: return
		oldRaw	   = inpRaw
		
		externalSensor=False
		sensorList=[]
		sensorsOld= copy.copy(sensors)


		
		U.getGlobalParams(inp)
		  
		if "sensorList"			in inp:	 sensorList=			 (inp["sensorList"])
		if "sensors"			in inp:	 sensors =				 (inp["sensors"])
		if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPISENSOR"])
		 
 
		if sensor not in sensors:
			U.toLog(-1, G.program+" is not in parameters = not enabled, stopping "+G.program+".py" )
			exit()
			

		U.toLog(-1, G.program+" reading new parameter file" )

		if sensorRefreshSecs == 91:
			try:
				xx	   = str(inp["sensorRefreshSecs"]).split("#")
				sensorRefreshSecs = float(xx[0]) 
			except:
				sensorRefreshSecs = 91	  
		deltaX={}
		restart = False
		for devId in sensors[sensor]:
			deltaX[devId]  = 0.1

			try:
				if "sensorRefreshSecs" in sensors[sensor][devId]:
					xx = sensors[sensor][devId]["sensorRefreshSecs"].split("#")
					sensorRefreshSecs = float(xx[0]) 
			except:
				sensorRefreshSecs = 5	 

			try:
				old = calibrationPin
				if "calibrationPin" in sensors[sensor][devId]:
					old = int(sensors[sensor][devId]["calibrationPin"])
			except:
				calibrationPin = 18	   
			if	calibrationPin != old:
				calibrationPin	= old 
				restart = True
			

			try:
				old = amplification
				if "amplification" in sensors[sensor][devId]:
					old = sensors[sensor][devId]["amplification"]
			except:
				amplification = 5000	
			if	amplification != old:
				amplification  = old 
				restart = True
			
			try:
				if "deltaX" in sensors[sensor][devId]: 
					deltaX[devId]= float(sensors[sensor][devId]["deltaX"])/100.
			except:
				deltaX[devId] = 0.1

			try:
				if "CO2normal" in sensors[sensor][devId]: 
					CO2normal[devId]= float(sensors[sensor][devId]["CO2normal"])
			except:
				CO2normal[devId] = 410

			try:
				if "CO2offset" in sensors[sensor][devId]: 
					CO2offset[devId]= float(sensors[sensor][devId]["CO2offset"])
			except:
				CO2offset[devId] = 0

			try:
				if "sensitivity" in sensors[sensor][devId]: 
					sensitivity[devId]= sensors[sensor][devId]["sensitivity"]
			except:
				sensitivity[devId] = "medium"

			try:
				if "timeaboveCalibrationMAX" in sensors[sensor][devId]: 
					timeaboveCalibrationMAX[devId]= float(sensors[sensor][devId]["sensitivity"])
			except:
				timeaboveCalibrationMAX[devId] = 1200


			try:
				if "minSendDelta" in sensors[sensor][devId]: 
					minSendDelta= float(sensors[sensor][devId]["minSendDelta"])
			except:
				minSendDelta = 5.

				
			if devId not in mhz19sensor or	restart:
				startSensor(devId, calibrationPin)
				if mhz19sensor[devId] =="":
					return
			U.toLog(-1," new parameters read:  minSendDelta:"+unicode(minSendDelta)+
					   ";  deltaX:"+unicode(deltaX[devId])+";  sensorRefreshSecs:"+unicode(sensorRefreshSecs) +"  restart:"+str(restart))
				
		deldevID={}		   
		for devId in mhz19sensor:
			if devId not in sensors[sensor]:
				deldevID[devId]=1
		for dd in  deldevID:
			del mhz19sensor[dd]
		if len(mhz19sensor) ==0: 
			####exit()
			pass


	except	Exception, e:
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
		print sensors[sensor]
예제 #32
0
파일: max31865.py 프로젝트: kw123/piBeacon
def readParams():
	global sensorList, sensors, logDir, sensor,	 sensorRefreshSecs
	global rawOld
	global deltaX, max31865sensor, minSendDelta
	global oldRaw, lastRead
	try:



		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return
		if lastRead2 == lastRead: return
		lastRead   = lastRead2
		if inpRaw == oldRaw: return
		oldRaw	   = inpRaw
		
		externalSensor=False
		sensorList=[]
		sensorsOld= copy.copy(sensors)


		
		U.getGlobalParams(inp)
		  
		if "sensorList"			in inp:	 sensorList=			 (inp["sensorList"])
		if "sensors"			in inp:	 sensors =				 (inp["sensors"])
		if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPISENSOR"])
		
 
		if sensor not in sensors:
			U.toLog(-1, G.program+" is not in parameters = not enabled, stopping "+G.program+".py" )
			exit()
			
				
		deltaX={}
		for devId in sensors[sensor]:
			deltaX[devId]  = 0.1
			try:
				xx = sensors[sensor][devId]["sensorRefreshSecs"].split("#")
				sensorRefreshSecs = float(xx[0]) 
			except:
				sensorRefreshSecs = 90	  


			try:
				if "GPIOcsPin" in sensors[sensor][devId]: 			GPIOcsPin = int(sensors[sensor][devId]["GPIOcsPin"])
			except:	GPIOcsPin = 8	   

			try:
				if "GPIOmisoPin" in sensors[sensor][devId]: 		GPIOmisoPin = int(sensors[sensor][devId]["GPIOmisoPin"])
			except:	GPIOmisoPin = 8	   

			try:
				if "GPIOmosiPin" in sensors[sensor][devId]: 		GPIOmosiPin = int(sensors[sensor][devId]["GPIOmosiPin"])
			except:	GPIOmosiPin = 8	   

			try:
				if "GPIOclkPin" in sensors[sensor][devId]: 			GPIOclkPin = int(sensors[sensor][devId]["GPIOclkPin"])
			except:	GPIOclkPin = 8	   

			try:
				if "nWires" in sensors[sensor][devId]: 				nWires = int(sensors[sensor][devId]["nWires"])
			except:	nWires = 3  

			try:
				if "referenceResistor" in sensors[sensor][devId]: 	referenceResistor = float(sensors[sensor][devId]["referenceResistor"])
			except:	referenceResistor = 4300	   


			try:
				if "resistorAt0C" in sensors[sensor][devId]: 		resistorAt0C = float(sensors[sensor][devId]["resistorAt0C"])
			except:	resistorAt0C = 1000	   


			try:
				if "hertz50_60" in sensors[sensor][devId]: 			hertz50_60 = int(sensors[sensor][devId]["hertz50_60"])
			except:	hertz50_60 = 60	   


			try:
				if "deltaX" in sensors[sensor][devId]: 
					deltaX[devId]= float(sensors[sensor][devId]["deltaX"])/100.
			except:
				deltaX[devId] = 0.05

			try:
				if "minSendDelta" in sensors[sensor][devId]: 
					minSendDelta= float(sensors[sensor][devId]["minSendDelta"])/100.
			except:
				minSendDelta = 5.

				
			if devId not in max31865sensor:
				U.toLog(-1,"==== Start "+G.program +";   devID: "+ str(devId)+";    R-at 0C: %d"%(resistorAt0C))
				max31865sensor[devId] = max31865(GPIOcsPin,GPIOmisoPin,GPIOmosiPin,GPIOclkPin,nWires,referenceResistor,resistorAt0C,hertz50_60)
				U.toLog(-1," started "+ str(devId))

				
		deldevID={}		   
		for devId in max31865sensor:
			if devId not in sensors[sensor]:
				deldevID[devId]=1
		for dd in  deldevID:
			del max31865sensor[dd]
		if len(max31865sensor) ==0: 
			####exit()
			pass

	except	Exception, e:
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #33
0
def readParams():
	global sensor, sensors
	global gpioIn , gpioSW1 ,gpioSW2, gpioSW5, gpioSWP, cyclePower, sensorMode
	global ON, off
	global oldRaw, lastRead
	global switchToLowerSensitive, switchToHigherSensitive, bucketSize,bucketSize0, sendMSGEverySecs
	global status
	try:
		restart = False


		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return
		if lastRead2 == lastRead: return
		lastRead  = lastRead2
		if inpRaw == oldRaw: return
		oldRaw	   = inpRaw


		oldSensors		  = sensors

		U.getGlobalParams(inp)
		if "sensors"			in inp : sensors =				(inp["sensors"])
		if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPISENSOR"])

		if sensor not in sensors:
			U.toLog(0,	"no "+ G.program+" sensor defined, exiting",doPrint=True)
			exit()

		sens= sensors[sensor]
		found ={str(ii):{"RISING":0,"GPIOchanged":0,"BOTH":0 } for ii in range(100)}
		for devId in sens:
			sss= sens[devId]
			if "gpioIn"					   not in sss: continue
			if "gpioSW5"				   not in sss: continue
			if "gpioSW2"				   not in sss: continue
			if "gpioSW1"				   not in sss: continue
			if "gpioSWP"				   not in sss: continue
			if "sensorMode"				   not in sss: continue
			
			cp	= sss["cyclePower"] != "0"

			if gpioIn != -1 and gpioIn != int(sss["gpioIn"]):
				restart = True
				U.toLog(0,	"gpios channel changed, need to restart",doPrint=True)
				U.restartMyself(param="", reason=" new gpioIn",doPrint=True)
				return 

			cyclePower = True 
			if gpioSWP != int(sss["gpioSWP"]):
				gpioSWP = int(sss["gpioSWP"])
				if gpioSWP >0: GPIO.setup(gpioSWP, GPIO.OUT)
				powerOFF(calledFrom="read")
			if gpioSW1 != int(sss["gpioSW1"]):
				gpioSW1 = int(sss["gpioSW1"])
				if gpioSW1 >0: GPIO.setup(gpioSW1, GPIO.OUT)
			if gpioSW2 != int(sss["gpioSW2"]):
				gpioSW2 = int(sss["gpioSW2"])
				if gpioSW2 >0: GPIO.setup(gpioSW2, GPIO.OUT)
			if gpioSW5 != int(sss["gpioSW5"]):
				gpioSW5 = int(sss["gpioSW5"])
				if gpioSW5 >0: GPIO.setup(gpioSW5, GPIO.OUT)
			switchToLowerSensitive["checkIfIsRaining"]	= 10# int(sss["TimeSwitchSensitivityRainToMayBeRaining"])
			switchToLowerSensitive["maybeRain"]			= 10# int(sss["TimeSwitchSensitivityMayBeRainingToHigh"])
			switchToLowerSensitive["highSensitive"]		= 10# int(sss["TimeSwitchSensitivityHighToMed"])
			switchToLowerSensitive["medSensitive"]		= 10# int(sss["TimeSwitchSensitivityMedToLow"])
			
			switchToHigherSensitive["lowSensitive"]		= 100# int(sss["TimeSwitchSensitivityLowToMed"])
			switchToHigherSensitive["medSensitive"]		= 100# int(sss["TimeSwitchSensitivityMedToHigh"])
			switchToHigherSensitive["highSensitive"]	= 100# int(sss["TimeSwitchSensitivityHighToAnyRain"])
			try: rainScaleFactor						= float(sss["rainScaleFactor"])
			except: rainScaleFactor						= 1.
				
			if gpioIn != int(sss["gpioIn"]):
				gpioIn	= int(sss["gpioIn"])
				GPIO.setup(gpioIn,	GPIO.IN, pull_up_down=GPIO.PUD_UP)
				GPIO.add_event_detect(gpioIn, GPIO.FALLING,		callback=GPIOchanged, bouncetime=100)  
				if sss["sensorMode"] != "dynamic":	setModeTo("checkIfIsRaining", calledFrom="readParams1")

			if sensorMode != sss["sensorMode"]:
				if sss["sensorMode"] != "dynamic":
					sendShortStatus(rainMsg["checkIfIsRaining"])
					nextModeSwitchNotBefore= time.time()+2
				setModeTo(sss["sensorMode"],force=True, calledFrom="readParams2")

			sensorMode									= sss["sensorMode"]
			sendMSGEverySecs							= float(sss["sendMSGEverySecs"])
			time.sleep(0.4)
			powerON(calledFrom="read")
			cyclePower = cp

			bucketSize={}
			for kk in bucketSize0:
				bucketSize[kk] = bucketSize0[kk]*rainScaleFactor

			
	except	Exception, e:
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e),doPrint=True)
예제 #34
0
def readParams():
    global sensors, sensor,  sensorRefreshSecs, dynamic, mode, deltaDist,displayEnable
    global output
    global distanceUnits
    global oldRaw, lastRead
    try:

        inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
        if inp == "": return
        if lastRead2 == lastRead: return
        lastRead   = lastRead2
        if inpRaw == oldRaw: return
        oldRaw     = inpRaw

        sensorsOld= copy.copy(sensors)
       
        U.getGlobalParams(inp)
         
        if "sensors"                in inp:  sensors =           (inp["sensors"])
        if "distanceUnits"          in inp:  distanceUnits=      (inp["distanceUnits"])
        if "debugRPI"           in inp:  G.debug=             int(inp["debugRPI"]["debugRPISENSOR"])
        
        if "output"                 in inp:  output=             (inp["output"])
   
 
        if sensor not in sensors:
            U.toLog(-1, "ultrasound is not in parameters = not enabled, stopping ultrasoundDistance.py" )
            exit()
            
 
        sensorUp = U.doWeNeedToStartSensor(sensors,sensorsOld,sensor)


        if sensorUp != 0: # something has changed
            if os.path.isfile(G.homeDir+"temp/"+sensor+".dat"):
                os.remove(G.homeDir+"temp/"+sensor+".dat")

        if sensorUp == 1:
            for devId in sensors[sensor]:
                GPIO.setwarnings(False)
                gpioPin= int(sensors[sensor][devId]["gpioTrigger"])
                GPIO.setup(gpioPin,  GPIO.OUT)
                gpioPin= int(sensors[sensor][devId]["gpioEcho"])
                GPIO.setup(gpioPin,  GPIO.IN,  pull_up_down = GPIO.PUD_UP)
        if sensorUp == -1:
            pass
            # stop sensor
        dynamic = False
        deltaDist={}
        for devId in sensors[sensor]:
            try:
                xx = sensors[sensor][devId]["sensorRefreshSecs"].split("#")
                sensorRefreshSecs = int(xx[0]) 
                if sensorRefreshSecs  < 0: dynamic=True
                if len(xx)==2: 
                    try: mode = int(xx[1])
                    except: mode =0
                
            except:
                sensorRefreshSecs = 100    
                mode =0

            try:
                if "displayEnable" in sensors[sensor][devId]: 
                    displayEnable = sensors[sensor][devId]["displayEnable"]
            except:
                display = False    


            deltaDist[devId]  = 0.1
            try:
                if "deltaDist" in sensors[sensor][devId]: 
                    deltaDist[devId]= float(sensors[sensor][devId]["deltaDist"])/100.
            except:
                pass

            try:
                if "units" in sensors[sensor][devId]:
                    units= sensors[sensor][devId]["units"]
                    distanceUnits = units
            except  Exception, e:
                pass


    except  Exception, e:
        U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #35
0
def readParams():
    global  sensorList, sensors, logDir, sensor,  sensorRefreshSecs, dynamic, mode, deltaDist,displayEnable
    global output, sensorActive, timing, tof, distanceUnits
    global actionDistanceOld, actionShortDistance, actionShortDistanceLimit, actionMediumDistance, actionMediumDistanceLimit, actionLongDistance, actionLongDistanceLimit
    global oldRaw, lastRead
    try:

        inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
        if inp == "": return
        if lastRead2 == lastRead: return
        lastRead   = lastRead2
        if inpRaw == oldRaw: return
        oldRaw     = inpRaw


        externalSensor=False
        sensorList=[]
        sensorsOld= copy.copy(sensors)
        
        U.getGlobalParams(inp)
          
        if "sensorList"         in inp:  sensorList=         (inp["sensorList"])
        if "sensors"            in inp:  sensors =           (inp["sensors"])
        if "debugRPI"           in inp:  G.debug=             int(inp["debugRPI"]["debugRPISENSOR"])
        if "distanceUnits"      in inp:  distanceUnits=      (inp["distanceUnits"])
        
        if "output"             in inp:  output=             (inp["output"])
   
 
        if sensor not in sensors:
            U.toLog(-1, "vlx503l0xDistance is not in parameters = not enabled, stopping vlx503l0xDistance.py" )
            exit()
            
 
        sensorUp = doWeNeedToStartSensor(sensors,sensorsOld,sensor)


        if sensorUp != 0: # something has changed
            if os.path.isfile(G.homeDir+"temp/"+sensor+".dat"):
                os.remove(G.homeDir+"temp/"+sensor+".dat")
                
        dynamic = False
        deltaDist={}
        for devId in sensors[sensor]:
            deltaDist[devId]  = 0.1
            try:
                xx = sensors[sensor][devId]["sensorRefreshSecs"].split("#")
                sensorRefreshSecs = int(xx[0]) 
                if sensorRefreshSecs  < 0: dynamic=True
                if len(xx)==2: 
                    try: mode = int(xx[1])
                    except: mode =0
            except:
                sensorRefreshSecs = 100    
                mode =0

            try:
                if "displayEnable" in sensors[sensor][devId]: 
                    displayEnable = sensors[sensor][devId]["displayEnable"]
            except:
                display = False    

            try:
                if "deltaDist" in sensors[sensor][devId]: 
                    deltaDist[devId]= float(sensors[sensor][devId]["deltaDist"])/100.
            except:
                pass
            try:
                if "dUnits" in sensors[sensor][devId] and sensors[sensor][devId]["dUnits"] !="":
                    distanceUnits = sensors[sensor][devId]["dUnits"]
            except  Exception, e:
                pass
            try:
                if "acuracyDistanceMode" in sensors[sensor][devId]:
                    acuracyDistanceMode= int(sensors[sensor][devId]["acuracyDistanceMode"])
            except: 
                acuracyDistanceMode = VL53L0X_LONG_RANGE_MODE
                pass

            try:
                if "actionShortDistance" in sensors[sensor][devId]:         actionShortDistance = (sensors[sensor][devId]["actionShortDistance"])
            except:                                                         actionShortDistance = ""

            try:
                if "actionMediumDistance" in sensors[sensor][devId]:        actionMediumDistance = (sensors[sensor][devId]["actionMediumDistance"])
            except:                                                         actionMediumDistance = ""

            try:
                if "actionLongDistance" in sensors[sensor][devId]:          actionLongDistance = (sensors[sensor][devId]["actionLongDistance"])
            except:                                                         actionLongDistance = ""


            try:
                if "actionShortDistanceLimit" in sensors[sensor][devId]:    actionShortDistanceLimit = float(sensors[sensor][devId]["actionShortDistanceLimit"])
            except:                                                         actionShortDistanceLimit = -1

            try:
                if "actionLongDistanceLimit" in sensors[sensor][devId]:     actionLongDistanceLimit = float(sensors[sensor][devId]["actionLongDistanceLimit"])
            except:                                                         actionLongDistanceLimit = -1


        if sensorUp == 1:
            if not sensorActive:
                U.toLog(-1,"==== Start ranging =====; mode= "+unicode(accuracyDistanceModes[acuracyDistanceMode]))
                startSensor(acuracyDistanceMode)

            elif acuracyDistanceMode != acuracyDistanceModeOld:
                U.toLog(-1, "==== re-Start ranging =====; mode= "+unicode(accuracyDistanceModes[acuracyDistanceMode]))
                tof.stop_ranging()
                startSensor(acuracyDistanceMode)
                
        if sensorUp == -1:
            tof.stop_ranging()
            U.toLog(-1, "==== stop  ranging =====")
            exit()
예제 #36
0
파일: si7021.py 프로젝트: kw123/piBeacon
def readParams():
	global sensorList, sensors, logDir, sensor,	 sensorRefreshSecs
	global rawOld
	global deltaX, SI7021sensor, minSendDelta
	global oldRaw, lastRead
	try:



		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return
		if lastRead2 == lastRead: return
		lastRead   = lastRead2
		if inpRaw == oldRaw: return
		oldRaw	   = inpRaw
		
		externalSensor=False
		sensorList=[]
		sensorsOld= copy.copy(sensors)


		
		U.getGlobalParams(inp)
		  
		if "sensorList"			in inp:	 sensorList=			 (inp["sensorList"])
		if "sensors"			in inp:	 sensors =				 (inp["sensors"])
		if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPISENSOR"])
		
 
		if sensor not in sensors:
			U.toLog(-1, G.program+" is not in parameters = not enabled, stopping "+G.program+".py" )
			exit()
			
				
		deltaX={}
		for devId in sensors[sensor]:
			deltaX[devId]  = 0.1
			try:
				xx = sensors[sensor][devId]["sensorRefreshSecs"].split("#")
				sensorRefreshSecs = float(xx[0]) 
			except:
				sensorRefreshSecs = 90	  


			try:
				if "i2cAddress" in sensors[sensor][devId]: 
					i2cAddress = int(sensors[sensor][devId]["i2cAddress"])
			except:
				i2cAddress = ""	   

			try:
				if "deltaX" in sensors[sensor][devId]: 
					deltaX[devId]= float(sensors[sensor][devId]["deltaX"])/100.
			except:
				deltaX[devId] = 0.05

			try:
				if "minSendDelta" in sensors[sensor][devId]: 
					minSendDelta= float(sensors[sensor][devId]["minSendDelta"])/100.
			except:
				minSendDelta = 5.

				
			if devId not in SI7021sensor:
				U.toLog(-1,"==== Start "+G.program+" ===== @ i2c= " +unicode(i2cAddress))
				i2cAdd = U.muxTCA9548A(sensors[sensor][devId])
				SI7021sensor[devId] = si7021(i2cAddress=i2cAdd)
				U.muxTCA9548Areset()
				
		deldevID={}		   
		for devId in SI7021sensor:
			if devId not in sensors[sensor]:
				deldevID[devId]=1
		for dd in  deldevID:
			del SI7021sensor[dd]
		if len(SI7021sensor) ==0: 
			####exit()
			pass

	except	Exception, e:
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #37
0
def readParams():
	global sensorList, sensors, logDir, sensor,	 sensorRefreshSecs
	global rawOld,i2cAddress
	global as3935sensor, minSendDelta
	global oldRaw, lastRead
	global startTime
	global inside, minStrikes, tuneCapacitor, minNoiseFloor, interruptGPIO,calibrationDynamic, noiseFloor, CapValue
	try:


		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return
		if lastRead2 == lastRead: return
		lastRead   = lastRead2
		if inpRaw == oldRaw: return
		oldRaw	   = inpRaw
		
		externalSensor=False
		sensorList=[]
		sensorsOld= copy.copy(sensors)


		
		U.getGlobalParams(inp)
		  
		if "sensorList"			in inp:	 sensorList=			 (inp["sensorList"])
		if "sensors"			in inp:	 sensors =				 (inp["sensors"])
		if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPISENSOR"])
		 
 
		if sensor not in sensors:
			U.toLog(-1, G.program+" is not in parameters = not enabled, stopping "+G.program+".py" )
			exit()
			

		U.toLog(-1, G.program+" reading new parameter file" )

		if sensorRefreshSecs == 91:
			try:
				xx	   = str(inp["sensorRefreshSecs"]).split("#")
				sensorRefreshSecs = float(xx[0]) 
			except:
				sensorRefreshSecs = 91	  
		deltaX={}
		restart = False
		for devId in sensors[sensor]:
			deltaX[devId]  = 0.1

			try:
				old = minStrikes
				if "minStrikes" in sensors[sensor][devId]:
					minStrikes = int(sensors[sensor][devId]["minStrikes"])
			except:
				minStrikes = 1	  
			if old != minStrikes: restart = True

			try:
				old = calibrationDynamic
				if "calibrationDynamic" in sensors[sensor][devId]:
					calibrationDynamic = int(sensors[sensor][devId]["calibrationDynamic"])
			except:
				calibrationDynamic = 1	  
			if old != calibrationDynamic: restart = True


			try:
				old = tuneCapacitor
				if "tuneCapacitor" in sensors[sensor][devId]:
					tuneCapacitor = int(sensors[sensor][devId]["tuneCapacitor"])
			except:
				tuneCapacitor = 15	  
			if old != tuneCapacitor: restart = True


			try:
				old = minNoiseFloor
				if "minNoiseFloor" in sensors[sensor][devId]:
					minNoiseFloor = int(sensors[sensor][devId]["minNoiseFloor"])
			except:
				minNoiseFloor = 2	
			if old != minNoiseFloor: restart = True

			try:
				old = noiseFloor
				if "noiseFloor" in sensors[sensor][devId]:
					noiseFloor = int(sensors[sensor][devId]["noiseFloor"])
			except:
				noiseFloor = 3	 
			if old != noiseFloor: restart = True

			old = inside
			try:
				if "inside" in sensors[sensor][devId]: 
					inside = int(sensors[sensor][devId]["inside"])
			except:
				inside = 0	 
			if old != inside: restart = True


			
			old = i2cAddress
			try:
				if "i2cAddress" in sensors[sensor][devId]: 
					i2cAddress = int(sensors[sensor][devId]["i2cAddress"])
			except:
				i2cAddress = ""	  
			if old != i2cAddress: restart = True


			try:
				if "interruptGPIO" in sensors[sensor][devId]: 
					interruptGPIO= int(sensors[sensor][devId]["interruptGPIO"])
			except:
				interruptGPIO = 17


			try:
				if "minSendDelta" in sensors[sensor][devId]: 
					minSendDelta= float(sensors[sensor][devId]["minSendDelta"])
			except:
				minSendDelta = 5.

				
			if devId not in as3935sensor or	 restart:
				startSensor(devId )
				if as3935sensor[devId] =="":
					return
				U.toLog(-1," new parameters read: \n  i2cAddress:" +unicode(i2cAddress) +";	 minSendDelta:"+unicode(minSendDelta)+";"+
						"  interruptGPIO:"+unicode(interruptGPIO)+";  sensorRefreshSecs:"+unicode(sensorRefreshSecs) +"\n"+
						"  minStrikes:"+unicode(minStrikes)		 +";  calibrationDynamic:"+unicode(calibrationDynamic) +"  inside:"+str(inside)+";"+
						"  tuneCapacitor:"+unicode(tuneCapacitor)+ " = "+CapValue[tuneCapacitor]+"pF;"+
						"  minNoiseFloor:"+unicode(minNoiseFloor)			+"	noiseFloor:"+str(noiseFloor)+"\n"+
						"  restart:"+str(restart),doPrint=True)
				
		deldevID={}		   
		for devId in as3935sensor:
			if devId not in sensors[sensor]:
				deldevID[devId]=1
		for dd in  deldevID:
			del as3935sensor[dd]
		if len(as3935sensor) ==0: 
			####exit()
			pass


	except	Exception, e:
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
		print sensors[sensor]
예제 #38
0
def readParams():
		global sensors
		global oldRaw, lastRead, INPUTS
		global counts, countSignals
		global useWhichGPIO, useThreads


		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return
		if lastRead2 == lastRead: return
		lastRead   = lastRead2
		if inpRaw == oldRaw: return
		oldRaw	   = inpRaw

		oldSensors  = sensors

		U.getGlobalParams(inp)
		if "sensors"			in inp : sensors =				(inp["sensors"])
		if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPISENSOR"])
		if oldSensors == sensors: return 

		restart = False
			
		if G.program  not in sensors:
			print G.program + "  not in sensors" 
			stopProgram()

		oldINPUTS  = copy.deepcopy(INPUTS)
		restart    = False
		if sensor in sensors:
			for devId in sensors[sensor]:
				new = False
				sens = sensors[sensor][devId]
				if devId not in INPUTS: 
					INPUTS[devId]  = {"pinALastValue":9999999, "incrementIfGT4Signals": "0", "lastChangeTime":0, "pinBLastValue":9999999, "pinA":21, "pinB":20, "inverse": True,"direction": 0, "newCycle":False, "distinctTransition":False, "ignorePinValue": "0","lastEvent": 0, "resetTimeCheck":0.001}
					#INPUTS[devId]["LockRotary"] = threading.Lock()		# create lock for rotary switch

				if devId not in counts:
					counts[devId] = 0
				if devId not in countSignals:
					countSignals[devId] = 0

				if "INPUT_0" in sens:
					if  INPUTS[devId]["pinA"] != int(sens["INPUT_0"]):
						INPUTS[devId]["pinA"]  = int(sens["INPUT_0"])
						new = True

				if "INPUT_1" in sens:
					if  INPUTS[devId]["pinB"] != int(sens["INPUT_1"]):
						INPUTS[devId]["pinB"]  = int(sens["INPUT_1"])
						new = True

				if "resetTimeCheck" in sens:
						INPUTS[devId]["resetTimeCheck"]  		= float(sens["resetTimeCheck"])

				if "inverse" in sens:
						INPUTS[devId]["inverse"]   				= (sens["inverse"] == "1")

				if "distinctTransition" in sens:
						INPUTS[devId]["distinctTransition"]		= (sens["distinctTransition"] == "1")

				if "ignorePinValue" in sens:
						INPUTS[devId]["ignorePinValue"] 		= int(sens["ignorePinValue"])

				if "incrementIfGT4Signals" in sens:
						INPUTS[devId]["incrementIfGT4Signals"]  = (sens["incrementIfGT4Signals"]=="1")

				if "useWhichGPIO" in sens:
						xxx 							 = sens["useWhichGPIO"].split("-")
						if  useWhichGPIO != xxx[0]:
							new = True
						if  useThreads != (xxx[1] == "threads"):
							new = True
						useWhichGPIO = xxx[0]
						useThreads	 = xxx[1] == "threads"
						
					
				if oldINPUTS != {} and new:
					restart = True
					break
				elif oldINPUTS == {} or new:
					startGPIO(devId)
		if restart:
			stopProgram(action ="onlyThread")
			U.restartMyself(reason="new parameters")
		return 
예제 #39
0
def readParams():
    global sensorList, sensors, logDir, sensor, sensorRefreshSecs, displayEnable
    global rawOld, i2cAddress
    global deltaX, mhz16, minSendDelta
    global oldRaw, lastRead
    global startTime
    global CO2normal, CO2offset, sensitivity, timeaboveCalibrationMAX
    try:

        inp, inpRaw, lastRead2 = U.doRead(lastTimeStamp=lastRead)
        if inp == "": return
        if lastRead2 == lastRead: return
        lastRead = lastRead2
        if inpRaw == oldRaw: return
        oldRaw = inpRaw

        externalSensor = False
        sensorList = []
        sensorsOld = copy.copy(sensors)

        U.getGlobalParams(inp)

        if "sensorList" in inp: sensorList = (inp["sensorList"])
        if "sensors" in inp: sensors = (inp["sensors"])
        if "debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPISENSOR"])

        if sensor not in sensors:
            U.toLog(
                -1,
                G.program + " is not in parameters = not enabled, stopping " +
                G.program + ".py")
            exit()

        U.toLog(-1, G.program + " reading new parameter file")

        if sensorRefreshSecs == 91:
            try:
                xx = str(inp["sensorRefreshSecs"]).split("#")
                sensorRefreshSecs = float(xx[0])
            except:
                sensorRefreshSecs = 91
        deltaX = {}
        restart = False
        for devId in sensors[sensor]:
            deltaX[devId] = 0.1

            try:
                if "sensorRefreshSecs" in sensors[sensor][devId]:
                    xx = sensors[sensor][devId]["sensorRefreshSecs"].split("#")
                    sensorRefreshSecs = float(xx[0])
            except:
                sensorRefreshSecs = 5

            old = i2cAddress
            try:
                if "i2cAddress" in sensors[sensor][devId]:
                    i2cAddress = int(sensors[sensor][devId]["i2cAddress"])
            except:
                i2cAddress = ""
            if old != i2cAddress: restart = True

            try:
                if "deltaX" in sensors[sensor][devId]:
                    deltaX[devId] = float(
                        sensors[sensor][devId]["deltaX"]) / 100.
            except:
                deltaX[devId] = 0.1

            try:
                if "CO2normal" in sensors[sensor][devId]:
                    CO2normal[devId] = float(
                        sensors[sensor][devId]["CO2normal"])
            except:
                CO2normal[devId] = 410

            try:
                if "CO2offset" in sensors[sensor][devId]:
                    CO2offset[devId] = float(
                        sensors[sensor][devId]["CO2offset"])
            except:
                CO2offset[devId] = 0

            try:
                if "sensitivity" in sensors[sensor][devId]:
                    sensitivity[devId] = sensors[sensor][devId]["sensitivity"]
            except:
                sensitivity[devId] = "medium"

            try:
                if "timeaboveCalibrationMAX" in sensors[sensor][devId]:
                    timeaboveCalibrationMAX[devId] = float(
                        sensors[sensor][devId]["sensitivity"])
            except:
                timeaboveCalibrationMAX[devId] = 1200

            try:
                if "minSendDelta" in sensors[sensor][devId]:
                    minSendDelta = float(
                        sensors[sensor][devId]["minSendDelta"])
            except:
                minSendDelta = 5.

            if devId not in mhz16sensor or restart:
                startSensor(devId, i2cAddress)
                if mhz16sensor[devId] == "":
                    return
            U.toLog(
                -1, " new parameters read: i2cAddress:" + unicode(i2cAddress) +
                ";	 minSendDelta:" + unicode(minSendDelta) + ";  deltaX:" +
                unicode(deltaX[devId]) + ";  sensorRefreshSecs:" +
                unicode(sensorRefreshSecs) + "  restart:" + str(restart))

        deldevID = {}
        for devId in mhz16sensor:
            if devId not in sensors[sensor]:
                deldevID[devId] = 1
        for dd in deldevID:
            del mhz16sensor[dd]
        if len(mhz16sensor) == 0:
            ####exit()
            pass

    except Exception, e:
        U.toLog(
            -1,
            u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
        print sensors[sensor]
예제 #40
0
def readParams():
		global debug, ipOfServer,myPiNumber,passwordOfServer, userIdOfServer, authentication,ipOfServer,portOfServer,sensorList,restartBLEifNoConnect
		global macList 
		global oldRaw, lastRead

		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return False
		if lastRead2 == lastRead: return False
		lastRead  = lastRead2
		if inpRaw == oldRaw: return False
		oldRaw	   = inpRaw

		oldSensor		  = sensorList

		try:

			U.getGlobalParams(inp)
			if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPIBLE"])
			if "restartBLEifNoConnect"	in inp:	 restartBLEifNoConnect=		  (inp["restartBLEifNoConnect"])
			if "sensorList"				in inp:	 sensorList=				  (inp["sensorList"])

			if "BLEconnect" not in sensorList:
				U.toLog(-1, u" no iphoneBLE definitions supplied (1) stopping")
				exit()
			if "sensors"				in inp:	 sensors=					  (inp["sensors"]["BLEconnect"])
			macListNew={}

			for devId in sensors :
					thisMAC = sensors[devId]["macAddress"]
					macListNew[thisMAC]={"iPhoneRefreshDownSecs":float(sensors[devId]["iPhoneRefreshDownSecs"]),
										 "iPhoneRefreshUpSecs":float(sensors[devId]["iPhoneRefreshUpSecs"]),
										 "BLEtimeout":float(sensors[devId]["BLEtimeout"]),
										 "up":False,
										 "lastTesttt":time.time()-1000.,
										 "lastMsgtt":time.time()-1000. ,
										 "lastData":"xx" ,
										 "quickTest": 0. ,
										 "devId": devId	 }
			for thisMAC in macListNew:
				if thisMAC not in macList:
					macList[thisMAC]=copy.copy(macListNew[thisMAC])
				else:
					macList[thisMAC]["iPhoneRefreshDownSecs"] = macListNew[thisMAC]["iPhoneRefreshDownSecs"]
					macList[thisMAC]["iPhoneRefreshUpSecs"]	  = macListNew[thisMAC]["iPhoneRefreshUpSecs"]
					macList[thisMAC]["BLEtimeout"]	 = macListNew[thisMAC]["BLEtimeout"]

			delMac={}
			for thisMAC in macList:
				if thisMAC not in macListNew:
					delMac[thisMAC]=1
			for	 thisMAC in delMac:
				del macList[thisMAC]

			if len(macList)	   == 0:
				U.toLog(-1, u" no BLEconnect definitions supplied stopping")
				exit()

			return True
			
		except	Exception, e:
			U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e),permanentLog=True)
예제 #41
0
def readParams():
    global sensors, sensor, sensorRefreshSecs, dynamic, mode, deltaDist, displayEnable
    global output
    global distanceUnits
    global oldRaw, lastRead
    try:

        inp, inpRaw, lastRead2 = U.doRead(lastTimeStamp=lastRead)
        if inp == "": return
        if lastRead2 == lastRead: return
        lastRead = lastRead2
        if inpRaw == oldRaw: return
        oldRaw = inpRaw

        sensorsOld = copy.copy(sensors)

        U.getGlobalParams(inp)

        if "sensors" in inp: sensors = (inp["sensors"])
        if "distanceUnits" in inp: distanceUnits = (inp["distanceUnits"])
        if "debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPISENSOR"])

        if "output" in inp: output = (inp["output"])

        if sensor not in sensors:
            U.toLog(
                -1,
                "ultrasound is not in parameters = not enabled, stopping ultrasoundDistance.py"
            )
            exit()

        sensorUp = U.doWeNeedToStartSensor(sensors, sensorsOld, sensor)

        if sensorUp != 0:  # something has changed
            if os.path.isfile(G.homeDir + "temp/" + sensor + ".dat"):
                os.remove(G.homeDir + "temp/" + sensor + ".dat")

        if sensorUp == 1:
            for devId in sensors[sensor]:
                GPIO.setwarnings(False)
                gpioPin = int(sensors[sensor][devId]["gpioTrigger"])
                GPIO.setup(gpioPin, GPIO.OUT)
                gpioPin = int(sensors[sensor][devId]["gpioEcho"])
                GPIO.setup(gpioPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        if sensorUp == -1:
            pass
            # stop sensor
        dynamic = False
        deltaDist = {}
        for devId in sensors[sensor]:
            try:
                xx = sensors[sensor][devId]["sensorRefreshSecs"].split("#")
                sensorRefreshSecs = int(xx[0])
                if sensorRefreshSecs < 0: dynamic = True
                if len(xx) == 2:
                    try:
                        mode = int(xx[1])
                    except:
                        mode = 0

            except:
                sensorRefreshSecs = 100
                mode = 0

            try:
                if "displayEnable" in sensors[sensor][devId]:
                    displayEnable = sensors[sensor][devId]["displayEnable"]
            except:
                display = False

            deltaDist[devId] = 0.1
            try:
                if "deltaDist" in sensors[sensor][devId]:
                    deltaDist[devId] = float(
                        sensors[sensor][devId]["deltaDist"]) / 100.
            except:
                pass

            try:
                if "units" in sensors[sensor][devId]:
                    units = sensors[sensor][devId]["units"]
                    distanceUnits = units
            except Exception, e:
                pass

    except Exception, e:
        U.toLog(
            -1,
            u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #42
0
def readParams():
    global sensorList, sensors, logDir, sensor, sensorRefreshSecs
    global rawOld
    global deltaX, as726xsensor, minSendDelta
    global oldRaw, lastRead
    global LEDmA, doAverage, LEDBlink, gain, integrationTime
    try:

        inp, inpRaw, lastRead2 = U.doRead(lastTimeStamp=lastRead)
        if inp == "": return
        if lastRead2 == lastRead: return
        lastRead = lastRead2
        if inpRaw == oldRaw: return
        oldRaw = inpRaw

        externalSensor = False
        sensorList = []
        sensorsOld = copy.copy(sensors)

        U.getGlobalParams(inp)

        if "sensorList" in inp: sensorList = (inp["sensorList"])
        if "sensors" in inp: sensors = (inp["sensors"])
        if "debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPISENSOR"])

        if sensor not in sensors:
            U.toLog(
                -1,
                G.program + " is not in parameters = not enabled, stopping " +
                G.program + ".py")
            exit()

        deltaX = {}
        for devId in sensors[sensor]:
            deltaX[devId] = 0.1
            try:
                xx = sensors[sensor][devId]["sensorRefreshSecs"].split("#")
                sensorRefreshSecs = float(xx[0])
            except:
                sensorRefreshSecs = 100

            try:
                if "i2cAddress" in sensors[sensor][devId]:
                    i2cAddress = int(sensors[sensor][devId]["i2cAddress"])
            except:
                i2cAddress = ""

            try:
                if "deltaX" in sensors[sensor][devId]:
                    deltaX[devId] = float(
                        sensors[sensor][devId]["deltaX"]) / 100.
            except:
                deltaX[devId] = 0.1

            try:
                if "minSendDelta" in sensors[sensor][devId]:
                    minSendDelta = float(
                        sensors[sensor][devId]["minSendDelta"]) / 100.
            except:
                minSendDelta = 5.

            try:
                if "gain" in sensors[sensor][devId]:
                    gain = float(sensors[sensor][devId]["gain"])
            except:
                gain = 16

            try:
                if "integrationTime" in sensors[sensor][devId]:
                    integrationTime = float(
                        sensors[sensor][devId]["integrationTime"])
            except:
                integrationTime = 140

            try:
                if "doAverage" in sensors[sensor][devId]:
                    doAverage = int(sensors[sensor][devId]["doAverage"])
            except:
                doAverage = 1

            try:
                if "LEDmA" in sensors[sensor][devId]:
                    LEDmA = float(sensors[sensor][devId]["LEDmA"])
            except:
                LEDmA = 5.

            try:
                if "LEDBlink" in sensors[sensor][devId]:
                    LEDBlink = int(sensors[sensor][devId]["LEDBlink"])
            except:
                LEDBlink = 0

            if devId not in as726xsensor:
                U.toLog(
                    -1, "==== Start " + G.program + " ====== @ i2c= " +
                    unicode(i2cAddress))
                i2cAdd = U.muxTCA9548A(sensors[sensor][devId])
                as726xsensor[devId] = Adafruit_AS726x(i2cAddress=i2cAdd)
                as726xsensor[devId].set_Conversion_mode(
                    as726xsensor[devId].MODE_2)
                U.muxTCA9548Areset()
            i2cAdd = U.muxTCA9548A(sensors[sensor][devId])
            as726xsensor[devId].set_Integration_time(integrationTime)
            as726xsensor[devId].set_Gain(gain)
            U.muxTCA9548Areset()

        deldevID = {}
        for devId in as726xsensor:
            if devId not in sensors[sensor]:
                deldevID[devId] = 1
        for dd in deldevID:
            del as726xsensor[dd]
        if len(as726xsensor) == 0:
            ####exit()
            pass

    except Exception, e:
        U.toLog(
            -1, u"readParams in Line '%s' has error='%s'" %
            (sys.exc_traceback.tb_lineno, e))
예제 #43
0
파일: as726x.py 프로젝트: kw123/piBeacon
def readParams():
	global sensorList, sensors, logDir, sensor,	 sensorRefreshSecs
	global rawOld
	global deltaX, as726xsensor, minSendDelta
	global oldRaw, lastRead
	global LEDmA, doAverage, LEDBlink, gain, integrationTime
	try:



		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return
		if lastRead2 == lastRead: return
		lastRead   = lastRead2
		if inpRaw == oldRaw: return
		oldRaw	   = inpRaw
		
		externalSensor=False
		sensorList=[]
		sensorsOld= copy.copy(sensors)


		
		U.getGlobalParams(inp)
		  
		if "sensorList"			in inp:	 sensorList=			 (inp["sensorList"])
		if "sensors"			in inp:	 sensors =				 (inp["sensors"])
		if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPISENSOR"])
		
 
		if sensor not in sensors:
			U.toLog(-1, G.program+" is not in parameters = not enabled, stopping "+G.program+".py" )
			exit()
			
				
		deltaX={}
		for devId in sensors[sensor]:
			deltaX[devId]  = 0.1
			try:
				xx = sensors[sensor][devId]["sensorRefreshSecs"].split("#")
				sensorRefreshSecs = float(xx[0]) 
			except:
				sensorRefreshSecs = 100	   


			try:
				if "i2cAddress" in sensors[sensor][devId]: 
					i2cAddress = int(sensors[sensor][devId]["i2cAddress"])
			except:
				i2cAddress = ""	   

			try:
				if "deltaX" in sensors[sensor][devId]: 
					deltaX[devId]= float(sensors[sensor][devId]["deltaX"])/100.
			except:
				deltaX[devId] = 0.1

			try:
				if "minSendDelta" in sensors[sensor][devId]: 
					minSendDelta= float(sensors[sensor][devId]["minSendDelta"])/100.
			except:
				minSendDelta = 5.

			try:
				if "gain" in sensors[sensor][devId]: 
					gain= float(sensors[sensor][devId]["gain"])
			except:
				gain = 16

			try:
				if "integrationTime" in sensors[sensor][devId]: 
					integrationTime= float(sensors[sensor][devId]["integrationTime"])
			except:
				integrationTime = 140

			try:
				if "doAverage" in sensors[sensor][devId]: 
					doAverage= int(sensors[sensor][devId]["doAverage"])
			except:
				doAverage = 1

			try:
				if "LEDmA" in sensors[sensor][devId]: 
					LEDmA= float(sensors[sensor][devId]["LEDmA"])
			except:
				LEDmA = 5.

			try:
				if "LEDBlink" in sensors[sensor][devId]: 
					LEDBlink= int(sensors[sensor][devId]["LEDBlink"])
			except:
				LEDBlink = 0



			if devId not in as726xsensor:
				U.toLog(-1,"==== Start "+G.program+" ====== @ i2c= " +unicode(i2cAddress) )
				i2cAdd = U.muxTCA9548A(sensors[sensor][devId])
				as726xsensor[devId] = Adafruit_AS726x(i2cAddress=i2cAdd)
				as726xsensor[devId].set_Conversion_mode(as726xsensor[devId].MODE_2)
				U.muxTCA9548Areset()
			i2cAdd = U.muxTCA9548A(sensors[sensor][devId])
			as726xsensor[devId].set_Integration_time(integrationTime)
			as726xsensor[devId].set_Gain(gain)
			U.muxTCA9548Areset()
			
		deldevID={}		   
		for devId in as726xsensor:
			if devId not in sensors[sensor]:
				deldevID[devId]=1
		for dd in  deldevID:
			del as726xsensor[dd]
		if len(as726xsensor) ==0: 
			####exit()
			pass

	except	Exception, e:
		U.toLog(-1, u"readParams in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
예제 #44
0
def readParams():
		global sensors,	 sensor, sensBase, oldSensParams
		global INPgpioType,INPUTcount,INPUTlastvalue,	oldParams
		global SCLPin, SDOPin
		global devClass16Serial,devClass16i2c,devClass12i2c, INPUTsensors,INPUTsensorTypes
		global oldRaw, lastRead

		INPUTcount = U.checkresetCount(INPUTcount)


		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return
		if lastRead2 == lastRead: return
		lastRead   = lastRead2
		if inpRaw == oldRaw: return
		oldRaw	   = inpRaw

		oldSensors		  = copy.copy(sensors)

		U.getGlobalParams(inp)
		if "sensors"			in inp : sensors =				(inp["sensors"])
		if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPISENSOR"])
		if oldSensors == sensors: return 

		INPUTsensorTypes=[]
		INPUTsensors={}
		for sensor in sensors:
			if "INPUTtouch" in sensor.split("-")[0]:
				if sensor not in INPUTsensors:
					INPUTsensors[sensor]=[]
				for devId in sensors[sensor]:
					if sensors[sensor][devId]["devType"] not in INPUTsensors[sensor]:
						INPUTsensors[sensor].append(sensors[sensor][devId]["devType"])
					if sensors[sensor][devId]["devType"] not in INPUTsensorTypes: INPUTsensorTypes.append(sensors[sensor][devId]["devType"])
				
		if	INPUTsensors == {}:
			exit()

	   
		for sen in INPUTsensors:
			for devId in sensors[sen]:
				if "devType"	   in sensors[sen][devId] : devType = sensors[sen][devId]["devType"]
				else: continue
				if devType not in INPUTsensorTypes: INPUTsensorTypes.append(devType)
				if devType == "16Serial":
					for nn in range(30):
						sen = sensBase+"-"+str(nn)
						if sen not in sensors: continue
						try:
							if "SCLPin" in sensors[sen][devId]: 
								SCLPin = int(sensors[sen][devId]["SCLPin"])
						except:
							SCLPin = 27	   
						try:
							if "SDOPin" in sensors[sen][devId]: 
								SDOPin = int(sensors[sen][devId]["SDOPin"])
						except:
							SCLPin = 22 
					if devClass16Serial =="":
						startTouch16Serial()
						devClass16i2Serial = "started"

				elif devType == "16i2c":
					if devClass16i2c =="":
						devClass16i2c = U.simpleI2cReadWrite(0x57, 1) 

				elif devType == "12i2c":
					if devClass12i2c =="":
						startTouch12i2c()
예제 #45
0

####################### main start ###############
PWM = 100


myPID = str(os.getpid())

try:	command = json.loads(sys.argv[1])
except: 
	U.toLog(-1, "setGPIO  bad json:" + unicode(sys.argv))
	exit()


inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=0)
U.getGlobalParams(inp)
U.getIPNumber() 

try:	G.debug= command["debug"]
except: G.debug = 1
G.debug = 3
U.toLog(0, "setGPIO  command :" + unicode(sys.argv))
try:	PWM= command["PWM"]
except: pass


if "cmd" in command:
	cmd= command["cmd"]
	if cmd not in allowedCommands:
		U.toLog(-1, G.program +" bad command " + command + "  allowed:" + unicode(allowedCommands))
		exit(1)
예제 #46
0
def readParams():
    global sensorList, sensors, logDir, sensor,  sensorRefreshSecs, dynamic, mode, deltaDist,displayEnable
    global output, sensorActive, timing, tof, distanceUnits
    global actionDistanceOld, actionShortDistance, actionShortDistanceLimit, actionLongDistance, actionLongDistanceLimit
    global distanceOffset, distanceMax
    global oldRaw, lastRead
    try:

        inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
        if inp == "": return
        if lastRead2 == lastRead: return
        lastRead   = lastRead2
        if inpRaw == oldRaw: return
        oldRaw     = inpRaw


        externalSensor=False
        sensorList=[]
        sensorsOld= copy.copy(sensors)

        U.getGlobalParams(inp)
          
        if "sensorList"         in inp:  sensorList=             (inp["sensorList"])
        if "sensors"            in inp:  sensors =               (inp["sensors"])
        if "distanceUnits"      in inp:  distanceUnits=          (inp["distanceUnits"])
        if "debugRPI"           in inp:  G.debug=             int(inp["debugRPI"]["debugRPISENSOR"])
        
        if "output"             in inp:  output=                 (inp["output"])
   
 
        if sensor not in sensors:
            U.toLog(-1, "40xx Distance  is not in parameters = not enabled, stopping vl6180xDistance.py" )
            exit()
            
 
        sensorChanged = doWeNeedToStartSensor(sensors,sensorsOld,sensor)


        if sensorChanged != 0: # something has changed
            if os.path.isfile(G.homeDir+"temp/"+sensor+".dat"):
                os.remove(G.homeDir+"temp/"+sensor+".dat")
                
        dynamic = False
        deltaDist={}
        for devId in sensors[sensor]:
            deltaDist[devId]  = 0.1
            try:
                xx = sensors[sensor][devId]["sensorRefreshSecs"].split("#")
                sensorRefreshSecs = int(xx[0]) 
                if sensorRefreshSecs  < 0: dynamic=True
                if len(xx)==2: 
                    try: mode = int(xx[1])
                    except: mode =0
            except:
                sensorRefreshSecs = 100    
                mode =0

            try:
                if "displayEnable" in sensors[sensor][devId]: 
                    displayEnable = sensors[sensor][devId]["displayEnable"]
            except:
                display = False    

            try:
                if "deltaDist" in sensors[sensor][devId]: 
                    deltaDist[devId]= float(sensors[sensor][devId]["deltaDist"])/100.
            except:
                pass
            try:
                if "dUnits" in sensors[sensor][devId] and sensors[sensor][devId]["dUnits"] !="":
                    distanceUnits = sensors[sensor][devId]["dUnits"]
            except  Exception, e:
                pass

            try:
                if "actionShortDistance" in sensors[sensor][devId]:         actionShortDistance = (sensors[sensor][devId]["actionShortDistance"])
            except:                                                         actionShortDistance = ""

            try:
                if "actionMediumDistance" in sensors[sensor][devId]:        actionMediumDistance = (sensors[sensor][devId]["actionMediumDistance"])
            except:                                                         actionMediumDistance = ""

            try:
                if "actionLongDistance" in sensors[sensor][devId]:          actionLongDistance = (sensors[sensor][devId]["actionLongDistance"])
            except:                                                         actionLongDistance = ""

            try:
                if "actionShortDistanceLimit" in sensors[sensor][devId]:    actionShortDistanceLimit = float(sensors[sensor][devId]["actionShortDistanceLimit"])
            except:                                                         actionShortDistanceLimit = -1

            try:
                if "actionLongDistanceLimit" in sensors[sensor][devId]:     actionLongDistanceLimit = float(sensors[sensor][devId]["actionLongDistanceLimit"])
            except:                                                         actionLongDistanceLimit = -1

            try:
                if True:                                                    maxCurrent = 8
                if "maxCurrent" in sensors[sensor][devId]:                  maxCurrent = int(sensors[sensor][devId]["maxCurrent"])
            except:                                                         maxCurrent = 8
            if devId not in distanceOffset:
                    distanceOffset[devId] = 2000
                    distanceMax[devId]    = int(5000*(maxCurrent/2.))

            #print sensorChanged, sensorActive, distanceMax
            if sensorChanged == 1:
                if not sensorActive:
                    U.toLog(-1,"==== Start ranging =====")
                    tof = VCNL40xx(address=0x13,maxCurrent=maxCurrent)
            sensorActive = True
            
            
        if sensorChanged == -1:
            U.toLog(-1, "==== stop  ranging =====")
            exit()
예제 #47
0
파일: setGPIO.py 프로젝트: kw123/piBeacon

####################### main start ###############
PWM = 100


myPID = str(os.getpid())

try:	command = json.loads(sys.argv[1])
except: 
	U.toLog(-1, "setGPIO  bad json:" + unicode(sys.argv))
	exit()


inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=0)
U.getGlobalParams(inp)
U.getIPNumber() 

try:	G.debug= command["debug"]
except: G.debug = 1
G.debug = 3
U.toLog(0, "setGPIO  command :" + unicode(sys.argv))
try:	PWM= command["PWM"]
except: pass


if "cmd" in command:
	cmd= command["cmd"]
	if cmd not in allowedCommands:
		U.toLog(-1, G.program +" bad command " + command + "  allowed:" + unicode(allowedCommands))
		exit(1)
예제 #48
0
def readParams():
    global sensorList, sensors, logDir, sensor, sensorRefreshSecs, displayEnable
    global rawOld
    global deltaX, BME680, minSendDelta
    global oldRaw, lastRead
    global startTime, calibrateIfgt, setCalibration, firstValue
    try:

        inp, inpRaw, lastRead2 = U.doRead(lastTimeStamp=lastRead)
        if inp == "": return
        if lastRead2 == lastRead: return
        lastRead = lastRead2
        if inpRaw == oldRaw: return
        oldRaw = inpRaw

        externalSensor = False
        sensorList = []
        sensorsOld = copy.copy(sensors)

        U.getGlobalParams(inp)

        if "sensorList" in inp: sensorList = (inp["sensorList"])
        if "sensors" in inp: sensors = (inp["sensors"])
        if "debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPISENSOR"])

        if sensor not in sensors:
            U.toLog(
                -1,
                "BME680 is not in parameters = not enabled, stopping BME680.py"
            )
            exit()

        U.toLog(1, "BME680 reading new parameter file")

        if sensorRefreshSecs == 91:
            try:
                xx = str(inp["sensorRefreshSecs"]).split("#")
                sensorRefreshSecs = float(xx[0])
            except:
                sensorRefreshSecs = 91
        deltaX = {}
        restart = False
        for devId in sensors[sensor]:
            deltaX[devId] = 0.1
            old = sensorRefreshSecs
            try:
                if "sensorRefreshSecs" in sensors[sensor][devId]:
                    xx = sensors[sensor][devId]["sensorRefreshSecs"].split("#")
                    sensorRefreshSecs = float(xx[0])
            except:
                sensorRefreshSecs = 91
            if old != sensorRefreshSecs: restart = True

            old = calibrateIfgt
            try:
                if "calibrateIfgt" in sensors[sensor][devId]:
                    calibrateIfgt = float(
                        sensors[sensor][devId]["calibrateIfgt"])
            except:
                calibrateIfgt = 110
            if old > 200 and calibrateIfgt < 200:
                restart = True  # switch from static to dyname, need to recalobarte = restart sensor

            try:
                if calibrateIfgt == 8888888.:
                    if "setCalibration" in sensors[sensor][devId]:
                        setCalibration = float(
                            sensors[sensor][devId]["setCalibration"])
                    else:
                        setCalibration = 0
                        calibrateIfgt = 110
                elif calibrateIfgt < 200:
                    setCalibration = 0
                elif calibrateIfgt == 9999999.:
                    try:
                        f = open(G.homeDir + "bme680.Calibration", "r")
                        setCalibration = json.loads(f.read())["resistance"]
                        f.close()
                    except:
                        calibrateIfgt = 110  # fallback if nothing in file
            except:
                setCalibration = 0
                calibrateIfgt = 110

            try:
                if "i2cAddress" in sensors[sensor][devId]:
                    i2cAddress = int(sensors[sensor][devId]["i2cAddress"])
            except:
                i2cAddress = ""

            old = deltaX[devId]
            try:
                if "deltaX" in sensors[sensor][devId]:
                    deltaX[devId] = float(
                        sensors[sensor][devId]["deltaX"]) / 100.
            except:
                deltaX[devId] = 0.1
            if old != deltaX[devId]: restart = True

            old = minSendDelta
            try:
                if "minSendDelta" in sensors[sensor][devId]:
                    minSendDelta = float(
                        sensors[sensor][devId]["minSendDelta"])
            except:
                minSendDelta = 5.
            if old != minSendDelta: restart = True

            if devId not in BMEsensor or restart:
                startSensor(devId, i2cAddress)
                if BMEsensor[devId] == "":
                    return
            U.toLog(
                -1, " new parameters read: i2cAddress:" + unicode(i2cAddress) +
                ";	 minSendDelta:" + unicode(minSendDelta) + ";  deltaX:" +
                unicode(deltaX[devId]) + ";  calibrateIfgt:" +
                unicode(calibrateIfgt) + ";  setCalibration:" +
                unicode(setCalibration) + ";	 sensorRefreshSecs:" +
                unicode(sensorRefreshSecs))

        deldevID = {}
        for devId in BMEsensor:
            if devId not in sensors[sensor]:
                deldevID[devId] = 1
        for dd in deldevID:
            del BMEsensor[dd]
        if len(BMEsensor) == 0:
            ####exit()
            pass

    except Exception, e:
        U.toLog(
            -1,
            u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
        print sensors[sensor]
예제 #49
0
def readParams():
    global sensors, sensor, sensBase, oldSensParams
    global INPgpioType, INPUTcount, INPUTlastvalue, oldParams
    global SCLPin, SDOPin
    global devClass16Serial, devClass16i2c, devClass12i2c, INPUTsensors, INPUTsensorTypes
    global oldRaw, lastRead

    INPUTcount = U.checkresetCount(INPUTcount)

    inp, inpRaw, lastRead2 = U.doRead(lastTimeStamp=lastRead)
    if inp == "": return
    if lastRead2 == lastRead: return
    lastRead = lastRead2
    if inpRaw == oldRaw: return
    oldRaw = inpRaw

    oldSensors = copy.copy(sensors)

    U.getGlobalParams(inp)
    if "sensors" in inp: sensors = (inp["sensors"])
    if "debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPISENSOR"])
    if oldSensors == sensors: return

    INPUTsensorTypes = []
    INPUTsensors = {}
    for sensor in sensors:
        if "INPUTtouch" in sensor.split("-")[0]:
            if sensor not in INPUTsensors:
                INPUTsensors[sensor] = []
            for devId in sensors[sensor]:
                if sensors[sensor][devId]["devType"] not in INPUTsensors[
                        sensor]:
                    INPUTsensors[sensor].append(
                        sensors[sensor][devId]["devType"])
                if sensors[sensor][devId]["devType"] not in INPUTsensorTypes:
                    INPUTsensorTypes.append(sensors[sensor][devId]["devType"])

    if INPUTsensors == {}:
        exit()

    for sen in INPUTsensors:
        for devId in sensors[sen]:
            if "devType" in sensors[sen][devId]:
                devType = sensors[sen][devId]["devType"]
            else:
                continue
            if devType not in INPUTsensorTypes:
                INPUTsensorTypes.append(devType)
            if devType == "16Serial":
                for nn in range(30):
                    sen = sensBase + "-" + str(nn)
                    if sen not in sensors: continue
                    try:
                        if "SCLPin" in sensors[sen][devId]:
                            SCLPin = int(sensors[sen][devId]["SCLPin"])
                    except:
                        SCLPin = 27
                    try:
                        if "SDOPin" in sensors[sen][devId]:
                            SDOPin = int(sensors[sen][devId]["SDOPin"])
                    except:
                        SCLPin = 22
                if devClass16Serial == "":
                    startTouch16Serial()
                    devClass16i2Serial = "started"

            elif devType == "16i2c":
                if devClass16i2c == "":
                    devClass16i2c = U.simpleI2cReadWrite(0x57, 1)

            elif devType == "12i2c":
                if devClass12i2c == "":
                    startTouch12i2c()
예제 #50
0
def readParams():
	global sensorList, sensors, logDir, sensor,	 sensorRefreshSecs, displayEnable
	global rawOld
	global deltaX, minSendDelta
	global oldRaw, lastRead
	global startTime
	global resetPin
	try:



		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return
		if lastRead2 == lastRead: return
		lastRead   = lastRead2
		if inpRaw == oldRaw: return
		oldRaw	   = inpRaw
		
		externalSensor=False
		sensorList=[]
		sensorsOld= copy.copy(sensors)


		
		U.getGlobalParams(inp)
		  
		if "sensorList"			in inp:	 sensorList=			 (inp["sensorList"])
		if "sensors"			in inp:	 sensors =				 (inp["sensors"])
		if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPISENSOR"])

 
		if sensor not in sensors:
			U.toLog(-1, G.program+" is not in parameters = not enabled, stopping BME680.py" )
			exit()
			

		U.toLog(1, G.program+" reading new parameter file" )


 

		if sensorRefreshSecs == 91:
			try:
				xx	   = str(inp["sensorRefreshSecs"]).split("#")
				sensorRefreshSecs = float(xx[0]) 
			except:
				sensorRefreshSecs = 91	  
		deltaX={}
		restart = False
		for devId in sensors[sensor]:
			deltaX[devId]  = 0.1
			if "resetPin"			in sensors[sensor][devId]:		resetPin[devId]= sensors[sensor][devId]["resetPin"]

			old = sensorRefreshSecs
			try:
				if "sensorRefreshSecs" in sensors[sensor][devId]:
					xx = sensors[sensor][devId]["sensorRefreshSecs"].split("#")
					sensorRefreshSecs = float(xx[0]) 
			except:
				sensorRefreshSecs = 12	  
			

			old = deltaX[devId]
			try:
				if "deltaX" in sensors[sensor][devId]: 
					deltaX[devId]= float(sensors[sensor][devId]["deltaX"])/100.
			except:
				deltaX[devId] = 0.15
			if old != deltaX[devId]: restart = True

			old = minSendDelta
			try:
				if "minSendDelta" in sensors[sensor][devId]: 
					minSendDelta= float(sensors[sensor][devId]["minSendDelta"])
			except:
				minSendDelta = 5.
			if old != minSendDelta: restart = True


				
			if devId not in thisSensor or  restart:
				startSensor(devId)
				if thisSensor[devId] =="":
					return
			U.toLog(-1," new parameters read: minSendDelta:"+unicode(minSendDelta)+"   deltaX:"+unicode(deltaX[devId])+";  sensorRefreshSecs:"+unicode(sensorRefreshSecs) )
				
		deldevID={}		   
		for devId in thisSensor:
			if devId not in sensors[sensor]:
				deldevID[devId]=1
		for dd in  deldevID:
			del thisSensor[dd]
		if len(thisSensor) ==0: 
			####exit()
			pass

	except	Exception, e:
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e),doPrint=True)
		U.toLog(-1,str(sensors[sensor]) )
예제 #51
0
def readParams():
    global sensorList, sensors, logDir, sensor, sensorRefreshSecs, dynamic, mode, deltaDist, displayEnable
    global output, sensorActive, timing, tof, distanceUnits, rawOld
    global actionDistanceOld, actionShortDistance, actionShortDistanceLimit, actionLongDistance, actionLongDistanceLimit
    global oldRaw, lastRead
    try:

        inp, inpRaw, lastRead2 = U.doRead(lastTimeStamp=lastRead)
        if inp == "": return
        if lastRead2 == lastRead: return
        lastRead = lastRead2
        if inpRaw == oldRaw: return
        oldRaw = inpRaw

        externalSensor = False
        sensorList = []
        sensorsOld = copy.copy(sensors)

        U.getGlobalParams(inp)

        if "sensorList" in inp: sensorList = (inp["sensorList"])
        if "sensors" in inp: sensors = (inp["sensors"])
        if "debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPISENSOR"])
        if "distanceUnits" in inp: distanceUnits = (inp["distanceUnits"])

        if "output" in inp: output = (inp["output"])

        if sensor not in sensors:
            U.toLog(
                -1,
                "vl6180xDistance is not in parameters = not enabled, stopping vl6180xDistance.py"
            )
            exit()

        sensorUp = doWeNeedToStartSensor(sensors, sensorsOld, sensor)

        if sensorUp != 0:  # something has changed
            if os.path.isfile(G.homeDir + "temp/" + sensor + ".dat"):
                os.remove(G.homeDir + "temp/" + sensor + ".dat")

        dynamic = False
        deltaDist = {}
        for devId in sensors[sensor]:
            deltaDist[devId] = 0.1
            try:
                xx = sensors[sensor][devId]["sensorRefreshSecs"].split("#")
                sensorRefreshSecs = int(xx[0])
                if sensorRefreshSecs < 0: dynamic = True
                if len(xx) == 2:
                    try:
                        mode = int(xx[1])
                    except:
                        mode = 0
            except:
                sensorRefreshSecs = 100
                mode = 0

            try:
                if "displayEnable" in sensors[sensor][devId]:
                    displayEnable = sensors[sensor][devId]["displayEnable"]
            except:
                display = False

            try:
                if "deltaDist" in sensors[sensor][devId]:
                    deltaDist[devId] = float(
                        sensors[sensor][devId]["deltaDist"]) / 100.
            except:
                pass
            try:
                if "dUnits" in sensors[sensor][
                        devId] and sensors[sensor][devId]["dUnits"] != "":
                    distanceUnits = sensors[sensor][devId]["dUnits"]
            except Exception, e:
                pass

            try:
                if "actionShortDistance" in sensors[sensor][devId]:
                    actionShortDistance = (
                        sensors[sensor][devId]["actionShortDistance"])
            except:
                actionShortDistance = ""

            try:
                if "actionMediumDistance" in sensors[sensor][devId]:
                    actionMediumDistance = (
                        sensors[sensor][devId]["actionMediumDistance"])
            except:
                actionMediumDistance = ""

            try:
                if "actionLongDistance" in sensors[sensor][devId]:
                    actionLongDistance = (
                        sensors[sensor][devId]["actionLongDistance"])
            except:
                actionLongDistance = ""

            try:
                if "actionShortDistanceLimit" in sensors[sensor][devId]:
                    actionShortDistanceLimit = float(
                        sensors[sensor][devId]["actionShortDistanceLimit"])
            except:
                actionShortDistanceLimit = -1

            try:
                if "actionLongDistanceLimit" in sensors[sensor][devId]:
                    actionLongDistanceLimit = float(
                        sensors[sensor][devId]["actionLongDistanceLimit"])
            except:
                actionLongDistanceLimit = -1

        if sensorUp == 1:
            if not sensorActive:
                if "i2cAddress" in sensors[sensor][devId]:
                    i2cAddress = int(sensors[sensor][devId]["i2cAddress"])
                else:
                    i2cAddress = 0x29
                tof = vl6180x(address=i2cAddress)
                U.toLog(-1, "==== Start ranging =====")
                #startSensor(0)

        if sensorUp == -1:
            U.toLog(-1, "==== stop  ranging =====")
            exit()
예제 #52
0
def readParams():
		global debug, ipOfServer,myPiNumber,passwordOfServer, userIdOfServer, authentication,ipOfServer,portOfServer,sensorList,restartBLEifNoConnect
		global macList 
		global oldRaw, lastRead

		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)
		if inp == "": return False
		if lastRead2 == lastRead: return False
		lastRead  = lastRead2
		if inpRaw == oldRaw: return False
		oldRaw	   = inpRaw

		oldSensor		  = sensorList

		try:

			U.getGlobalParams(inp)
			if "debugRPI"			in inp:	 G.debug=			  int(inp["debugRPI"]["debugRPIBLE"])
			if "restartBLEifNoConnect"	in inp:	 restartBLEifNoConnect=		  (inp["restartBLEifNoConnect"])
			if "sensorList"				in inp:	 sensorList=				  (inp["sensorList"])

			if "BLEconnect" not in sensorList:
				U.toLog(-1, u" no iphoneBLE definitions supplied (1) stopping")
				exit()
			if "sensors"				in inp:	 sensors=					  (inp["sensors"]["BLEconnect"])
			macListNew={}

			for devId in sensors :
					thisMAC = sensors[devId]["macAddress"]
					macListNew[thisMAC]={"iPhoneRefreshDownSecs":float(sensors[devId]["iPhoneRefreshDownSecs"]),
										 "iPhoneRefreshUpSecs":float(sensors[devId]["iPhoneRefreshUpSecs"]),
										 "BLEtimeout":float(sensors[devId]["BLEtimeout"]),
										 "up":False,
										 "lastTesttt":time.time()-1000.,
										 "lastMsgtt":time.time()-1000. ,
										 "lastData":"xx" ,
										 "quickTest": 0. ,
										 "devId": devId	 }
			for thisMAC in macListNew:
				if thisMAC not in macList:
					macList[thisMAC]=copy.copy(macListNew[thisMAC])
				else:
					macList[thisMAC]["iPhoneRefreshDownSecs"] = macListNew[thisMAC]["iPhoneRefreshDownSecs"]
					macList[thisMAC]["iPhoneRefreshUpSecs"]	  = macListNew[thisMAC]["iPhoneRefreshUpSecs"]
					macList[thisMAC]["BLEtimeout"]	 = macListNew[thisMAC]["BLEtimeout"]

			delMac={}
			for thisMAC in macList:
				if thisMAC not in macListNew:
					delMac[thisMAC]=1
			for	 thisMAC in delMac:
				del macList[thisMAC]

			if len(macList)	   == 0:
				U.toLog(-1, u" no BLEconnect definitions supplied stopping")
				exit()

			return True
			
		except	Exception, e:
			U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e),permanentLog=True)
예제 #53
0
def readParams():
	global sensor, output, inpRaw, inp, DEVID,useRTC
	global clockDict, devTypeLEDs, speed, speedOfChange, clockLightSet,setClock, clockMode, gpiopinSET, clockLightSensor, minLightNotOff
	global lastCl, timeZone, currTZ
	global oldRaw, lastRead
	global doReadParameters
	try:

		if not doReadParameters: return
		changed =0
		inpLast= inp
		inp,inpRaw,lastRead2 = U.doRead(lastTimeStamp=lastRead)

		if inp == "": 
			inp = inpLast
			return changed
			
		if lastRead2 == lastRead: return changed
		lastRead  = lastRead2
		if inpRaw == "error":
			U.checkParametersFile("parameters-DEFAULT-clock", force = True)
		if inpRaw == oldRaw: return changed
		oldRaw	   = inpRaw
		U.getGlobalParams(inp)
		 
		if "debugRPI"				in inp:	 G.debug=		  int(inp["debugRPI"]["debugRPIOUTPUT"])
		if "useRTC"					in inp:	 useRTC=			 (inp["useRTC"])
		if "output"					in inp:	 output=			 (inp["output"])
		if "minLightNotOff"			in inp:	 minLightNotOff=  int(inp["minLightNotOff"])
		#### G.debug = 2 
		if "neopixelClock" not in output:
			U.toLog(-1, "neopixel-clock	 is not in parameters = not enabled, stopping "+ G.program+".py" )
			exit()
		clockLightSensor =0
		if "clockLightSensor"			in inp: 
			try:	xx = float(inp["clockLightSensor"])
			except: xx = 0
			clockLightSensor =xx

		clock = output["neopixelClock"]
		for devId in  clock:
			DEVID = devId
			clockDict= clock[devId][0]
			clu= unicode(clockDict)
			if lastCl == clu: 
				return changed

			lastCl = clu
			if "devTypeLEDs"	 not in clockDict: continue
			#if clockDict		!= "start" and json.dumps(clockDict)  != json.dumps(cl["neoPixelClock"]):	return 1
			changed = 1
			if "devTypeLEDs"	 in clockDict: 
				if devTypeLEDs !="start" and devTypeLEDs != clockDict["devTypeLEDs"]:
					changed = 2	  
				devTypeLEDs		=  clockDict["devTypeLEDs"]
			else:
					changed = 3	  
			if "timeZone"			 in clockDict:	
				if timeZone !=			   (clockDict["timeZone"]):
					changed = max(2, changed)  
					timeZone =				   (clockDict["timeZone"])
					tznew  = int(timeZone.split(" ")[0])
					if tznew != currTZ:
						U.toLog(-1, u"changing timezone from "+str(currTZ)+"  "+G.timeZones[currTZ+12]+" to "+str(tznew)+"  "+G.timeZones[tznew+12])
						os.system("sudo cp /usr/share/zoneinfo/"+G.timeZones[tznew+12]+" /etc/localtime")
						currTZ = tznew

			clockDict["timeZone"] = str(currTZ)+" "+ G.timeZones[currTZ+12]
				
			if "speedOfChange"	 in clockDict: speedOfChange   =  clockDict["speedOfChange"]
			if "speed"			 in clockDict: speed		   =  clockDict["speed"]

			if "clockLightSet"	 in clockDict: 
				xx											   =  clockDict["clockLightSet"]
				if	xx != clockLightSet:
					changed	  = max(changed,1)
				clockLightSet = xx
			try:
				if "GPIOsetA"			 in clockDict: gpiopinSET["setA"]			 =	int(clockDict["GPIOsetA"])
				if "GPIOsetB"			 in clockDict: gpiopinSET["setB"]			 =	int(clockDict["GPIOsetB"])
				if "GPIOsetC"			 in clockDict: gpiopinSET["setC"]			 =	int(clockDict["GPIOsetC"])
				if "GPIOup"				 in clockDict: gpiopinSET["up"]				 =	int(clockDict["GPIOup"])
				if "GPIOdown"			 in clockDict: gpiopinSET["down"]			 =	int(clockDict["GPIOdown"])
			except:
				pass

			## print clockDict
			break
		if devTypeLEDs == "start":	   changed = 3	# = no data inout restart myself in some seconds
		if changed ==2 : saveParameters()
		return changed

	except	Exception, e:
		print  u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e)
		U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
		time.sleep(10)
		return 3
예제 #54
0
def readParams():
    global sensorList, sensors, logDir, sensor, sensorRefreshSecs, displayEnable
    global rawOld
    global deltaX, minSendDelta
    global oldRaw, lastRead
    global startTime
    global resetPin
    try:

        inp, inpRaw, lastRead2 = U.doRead(lastTimeStamp=lastRead)
        if inp == "": return
        if lastRead2 == lastRead: return
        lastRead = lastRead2
        if inpRaw == oldRaw: return
        oldRaw = inpRaw

        externalSensor = False
        sensorList = []
        sensorsOld = copy.copy(sensors)

        U.getGlobalParams(inp)

        if "sensorList" in inp: sensorList = (inp["sensorList"])
        if "sensors" in inp: sensors = (inp["sensors"])
        if "debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPISENSOR"])

        if sensor not in sensors:
            U.toLog(
                -1, G.program +
                " is not in parameters = not enabled, stopping BME680.py")
            exit()

        U.toLog(1, G.program + " reading new parameter file")

        if sensorRefreshSecs == 91:
            try:
                xx = str(inp["sensorRefreshSecs"]).split("#")
                sensorRefreshSecs = float(xx[0])
            except:
                sensorRefreshSecs = 91
        deltaX = {}
        restart = False
        for devId in sensors[sensor]:
            deltaX[devId] = 0.1
            if "resetPin" in sensors[sensor][devId]:
                resetPin[devId] = sensors[sensor][devId]["resetPin"]

            old = sensorRefreshSecs
            try:
                if "sensorRefreshSecs" in sensors[sensor][devId]:
                    xx = sensors[sensor][devId]["sensorRefreshSecs"].split("#")
                    sensorRefreshSecs = float(xx[0])
            except:
                sensorRefreshSecs = 12

            old = deltaX[devId]
            try:
                if "deltaX" in sensors[sensor][devId]:
                    deltaX[devId] = float(
                        sensors[sensor][devId]["deltaX"]) / 100.
            except:
                deltaX[devId] = 0.15
            if old != deltaX[devId]: restart = True

            old = minSendDelta
            try:
                if "minSendDelta" in sensors[sensor][devId]:
                    minSendDelta = float(
                        sensors[sensor][devId]["minSendDelta"])
            except:
                minSendDelta = 5.
            if old != minSendDelta: restart = True

            if devId not in thisSensor or restart:
                startSensor(devId)
                if thisSensor[devId] == "":
                    return
            U.toLog(
                -1, " new parameters read: minSendDelta:" +
                unicode(minSendDelta) + "   deltaX:" + unicode(deltaX[devId]) +
                ";  sensorRefreshSecs:" + unicode(sensorRefreshSecs))

        deldevID = {}
        for devId in thisSensor:
            if devId not in sensors[sensor]:
                deldevID[devId] = 1
        for dd in deldevID:
            del thisSensor[dd]
        if len(thisSensor) == 0:
            ####exit()
            pass

    except Exception, e:
        U.toLog(-1,
                u"in Line '%s' has error='%s'" %
                (sys.exc_traceback.tb_lineno, e),
                doPrint=True)
        U.toLog(-1, str(sensors[sensor]))
예제 #55
0
def readParams():
    global sensor, sensors
    global INPgpioType, INPUTcount, INPUTlastvalue
    global GPIOdict, restart
    global oldRaw, lastRead
    try:
        restart = False

        inp, inpRaw, lastRead2 = U.doRead(lastTimeStamp=lastRead)
        if inp == "": return
        if lastRead2 == lastRead: return
        lastRead = lastRead2
        if inpRaw == oldRaw: return
        oldRaw = inpRaw

        oldSensors = sensors

        U.getGlobalParams(inp)
        if "sensors" in inp: sensors = (inp["sensors"])
        if "debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPISENSOR"])

        if sensor not in sensors:
            U.toLog(0,
                    "no " + G.program + " sensor defined, exiting",
                    doPrint=True)
            exit()

        sens = sensors[sensor]
        #print "sens:", sens
        found = {
            str(ii): {
                "RISING": 0,
                "FALLING": 0,
                "BOTH": 0
            }
            for ii in range(100)
        }
        for devId in sens:
            sss = sens[devId]
            if "gpio" not in sss: continue
            if "deadTime" not in sss: continue
            if "risingOrFalling" not in sss: continue
            if "minSendDelta" not in sss: continue
            if "bounceTime" not in sss: continue
            if "deadTime" not in sss: continue
            if "deadTimeBurst" not in sss: continue
            if "inpType" not in sss: continue
            if "timeWindowForBursts" not in sss: continue
            if "timeWindowForLongEvents" not in sss: continue
            if "timeWindowForContinuousEvents" not in sss: continue
            if "minBurstsinTimeWindowToTrigger" not in sss: continue

            gpio = sss["gpio"]
            risingOrFalling = sss["risingOrFalling"]
            inpType = sss["inpType"]

            try:
                bounceTime = int(sss["bounceTime"])
            except:
                bounceTime = 10

            try:
                timeWindowForLongEvents = float(sss["timeWindowForLongEvents"])
            except:
                timeWindowForLongEvents = -1

            try:
                minSendDelta = int(sss["minSendDelta"])
            except:
                minSendDelta = 1

            try:
                deadTime = float(sss["deadTime"])
            except:
                deadTime = 1

            try:
                deadTimeBurst = float(sss["deadTimeBurst"])
            except:
                deadTimeBurst = 1

            try:
                timeWindowForBursts = int(sss["timeWindowForBursts"])
            except:
                timeWindowForBursts = -1

            try:
                minBurstsinTimeWindowToTrigger = int(
                    sss["minBurstsinTimeWindowToTrigger"])
            except:
                minBurstsinTimeWindowToTrigger = -1

            try:
                timeWindowForLongEvents = float(sss["timeWindowForLongEvents"])
            except:
                timeWindowForLongEvents = -1

            try:
                pulseEveryXXsecsLongEvents = float(
                    sss["pulseEveryXXsecsLongEvents"])
            except:
                pulseEveryXXsecsLongEvents = -1

            try:
                timeWindowForContinuousEvents = float(
                    sss["timeWindowForContinuousEvents"])
            except:
                timeWindowForContinuousEvents = -1

            found[gpio][risingOrFalling] = 1
            if gpio in GPIOdict and "risingOrFalling" in GPIOdict[gpio]:
                if GPIOdict[gpio]["bounceTime"] != bounceTime:
                    restart = True
                    return
                if GPIOdict[gpio]["risingOrFalling"] != risingOrFalling:
                    restart = True
                    return
                GPIOdict[gpio]["deadTime"] = deadTime
                GPIOdict[gpio]["deadTimeBurst"] = deadTimeBurst
                GPIOdict[gpio]["devId"] = devId
                GPIOdict[gpio]["minSendDelta"] = minSendDelta
                GPIOdict[gpio][
                    "minBurstsinTimeWindowToTrigger"] = minBurstsinTimeWindowToTrigger
                GPIOdict[gpio]["timeWindowForBursts"] = timeWindowForBursts
                GPIOdict[gpio][
                    "timeWindowForLongEvents"] = timeWindowForLongEvents
                GPIOdict[gpio][
                    "timeWindowForContinuousEvents"] = timeWindowForContinuousEvents
                GPIOdict[gpio][
                    "pulseEveryXXsecsLongEvents"] = pulseEveryXXsecsLongEvents
                GPIOdict[gpio]["lastsendBurst"] = 0
                GPIOdict[gpio]["lastsendCount"] = 0
                GPIOdict[gpio]["lastsendlongEvent"] = 0
                GPIOdict[gpio]["lastsendContinuousEvent"] = 0
                if inpType != GPIOdict[gpio]["inpType"]:
                    if inpType == "open":
                        GPIO.setup(int(gpio), GPIO.IN)
                    elif inpType == "high":
                        GPIO.setup(int(gpio),
                                   GPIO.IN,
                                   pull_up_down=GPIO.PUD_UP)
                    elif inpType == "low":
                        GPIO.setup(int(gpio),
                                   GPIO.IN,
                                   pull_up_down=GPIO.PUD_DOWN)
                GPIOdict[gpio]["inpType"] = inpType
                continue
            elif gpio in GPIOdict and "risingOrFalling" not in GPIOdict[gpio]:
                print "setting up ", risingOrFalling
                GPIOdict[gpio] = {
                    "devId": devId,
                    "inpType": inpType,
                    "minSendDelta": minSendDelta,
                    "bounceTime": bounceTime,
                    "deadTime": deadTime,
                    "deadTimeBurst": deadTimeBurst,
                    "risingOrFalling": risingOrFalling,
                    "timeWindowForBursts": timeWindowForBursts,
                    "timeWindowForLongEvents": timeWindowForLongEvents,
                    "pulseEveryXXsecsLongEvents": pulseEveryXXsecsLongEvents,
                    "timeWindowForContinuousEvents":
                    timeWindowForContinuousEvents,
                    "minBurstsinTimeWindowToTrigger":
                    minBurstsinTimeWindowToTrigger,
                    "lastSignal": 0,
                    "lastsendCount": 0,
                    "lastsendBurst": 0,
                    "lastsendlongEvent": 0,
                    "lastsendContinuousEvent": 0,
                    "count": 0
                }
                print GPIOdict
                if inpType == "open":
                    GPIO.setup(int(gpio), GPIO.IN)
                elif inpType == "high":
                    GPIO.setup(int(gpio), GPIO.IN, pull_up_down=GPIO.PUD_UP)
                elif inpType == "low":
                    GPIO.setup(int(gpio), GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
                if risingOrFalling == "RISING":
                    GPIO.add_event_detect(int(gpio),
                                          GPIO.RISING,
                                          callback=RISING,
                                          bouncetime=bounceTime)
                elif risingOrFalling == "FALLING":
                    GPIO.add_event_detect(int(gpio),
                                          GPIO.FALLING,
                                          callback=FALLING,
                                          bouncetime=bounceTime)
                else:
                    GPIO.add_event_detect(int(gpio),
                                          GPIO.BOTH,
                                          callback=BOTH,
                                          bouncetime=bounceTime)
                GPIOdict[gpio]["inpType"] = inpType

            elif gpio not in GPIOdict:  # change: reboot
                GPIOdict[gpio] = {
                    "devId": devId,
                    "inpType": inpType,
                    "minSendDelta": minSendDelta,
                    "bounceTime": bounceTime,
                    "deadTime": deadTime,
                    "deadTimeBurst": deadTimeBurst,
                    "risingOrFalling": risingOrFalling,
                    "timeWindowForBursts": timeWindowForBursts,
                    "timeWindowForLongEvents": timeWindowForLongEvents,
                    "pulseEveryXXsecsLongEvents": pulseEveryXXsecsLongEvents,
                    "timeWindowForContinuousEvents":
                    timeWindowForContinuousEvents,
                    "minBurstsinTimeWindowToTrigger":
                    minBurstsinTimeWindowToTrigger,
                    "lastSignal": 0,
                    "lastsendCount": 0,
                    "lastsendBurst": 0,
                    "lastsendlongEvent": 0,
                    "lastsendContinuousEvent": 0,
                    "count": 0
                }
                print ""
                if inpType == "open":
                    GPIO.setup(int(gpio), GPIO.IN)
                elif inpType == "high":
                    GPIO.setup(int(gpio), GPIO.IN, pull_up_down=GPIO.PUD_UP)
                elif inpType == "low":
                    GPIO.setup(int(gpio), GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
                if risingOrFalling == "RISING":
                    GPIO.add_event_detect(int(gpio),
                                          GPIO.RISING,
                                          callback=RISING,
                                          bouncetime=bounceTime)
                elif risingOrFalling == "FALLING":
                    GPIO.add_event_detect(int(gpio),
                                          GPIO.FALLING,
                                          callback=FALLING,
                                          bouncetime=bounceTime)
                else:
                    GPIO.add_event_detect(int(gpio),
                                          GPIO.BOTH,
                                          callback=BOTH,
                                          bouncetime=bounceTime)
                GPIOdict[gpio]["inpType"] = inpType

        oneFound = False
        restart = False
        delGPIO = {}
        for gpio in GPIOdict:
            for risingOrFalling in ["FALLING", "RISING", "BOTH"]:
                if found[gpio][risingOrFalling] == 1:
                    oneFound = True
                    continue
                if risingOrFalling in GPIOdict:
                    restart = True
                    continue
            if GPIOdict[gpio] == {}: delGPIO[gpio] = 1
        for gpio in delGPIO:
            if gpio in GPIOdict: del GPIOdict[gpio]

        if not oneFound:
            U.toLog(0, "no	 gpios setup, exiting", doPrint=True)
            exit()
        if restart:
            U.toLog(0,
                    "gpios edge channel deleted, need to restart",
                    doPrint=True)
            U.restartMyself(param="", reason=" new definitions", doPrint=True)

        U.toLog(0, "GPIOdict: " + unicode(GPIOdict), doPrint=True)
    except Exception, e:
        U.toLog(-1,
                u"in Line '%s' has error='%s'" %
                (sys.exc_traceback.tb_lineno, e),
                doPrint=True)
예제 #56
0
def readParams():
    global sensorList, sensors, logDir, sensor, sensorRefreshSecs
    global rawOld
    global deltaX, INAsensor, minSendDelta
    global oldRaw, lastRead
    try:

        inp, inpRaw, lastRead2 = U.doRead(lastTimeStamp=lastRead)
        if inp == "": return
        if lastRead2 == lastRead: return
        lastRead = lastRead2
        if inpRaw == oldRaw: return
        oldRaw = inpRaw

        externalSensor = False
        sensorList = []
        sensorsOld = copy.copy(sensors)

        U.getGlobalParams(inp)

        if "sensorList" in inp: sensorList = (inp["sensorList"])
        if "sensors" in inp: sensors = (inp["sensors"])
        if "debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPISENSOR"])

        if sensor not in sensors:
            U.toLog(
                -1,
                G.program + " is not in parameters = not enabled, stopping " +
                G.program + ".py")
            exit()

        deltaX = {}
        for devId in sensors[sensor]:
            deltaX[devId] = 0.1
            try:
                xx = sensors[sensor][devId]["sensorRefreshSecs"].split("#")
                sensorRefreshSecs = float(xx[0])
            except:
                sensorRefreshSecs = 90

            try:
                if "i2cAddress" in sensors[sensor][devId]:
                    i2cAddress = int(sensors[sensor][devId]["i2cAddress"])
            except:
                i2cAddress = ""

            try:
                if "deltaX" in sensors[sensor][devId]:
                    deltaX[devId] = float(
                        sensors[sensor][devId]["deltaX"]) / 100.
            except:
                deltaX[devId] = 0.1

            try:
                if "minSendDelta" in sensors[sensor][devId]:
                    minSendDelta = float(
                        sensors[sensor][devId]["minSendDelta"]) / 100.
            except:
                minSendDelta = 5.

            try:
                if "minSendDelta" in sensors[sensor][devId]:
                    minSendDelta = float(
                        sensors[sensor][devId]["minSendDelta"]) / 100.
            except:
                minSendDelta = 5.

            try:
                shuntResistor = 0.1
                if "shuntResistor" in sensors[sensor][devId]:
                    shuntResistor = float(
                        sensors[sensor][devId]["shuntResistor"])
            except:
                shuntResistor = 0.1

            if devId not in INAsensor:
                U.toLog(
                    -1, "==== Start " + G.program + " ===== @ i2c= " +
                    unicode(i2cAddress) + ";	  shuntResistor= " +
                    unicode(shuntResistor))
                i2cAdd = U.muxTCA9548A(sensors[sensor][devId])
                INAsensor[devId] = INA219(i2cAddress=i2cAdd,
                                          shuntResistor=shuntResistor)
                U.muxTCA9548Areset()

        deldevID = {}
        for devId in INAsensor:
            if devId not in sensors[sensor]:
                deldevID[devId] = 1
        for dd in deldevID:
            del INAsensor[dd]
        if len(INAsensor) == 0:
            ####exit()
            pass

    except Exception, e:
        U.toLog(
            -1,
            u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))