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
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")
def readParams(): inp,inpRaw = U.doRead() if inp == "": return try: if u"debugRPI" in inp: debug= int(inp["debugRPI"]["debugRPImystuff"]) except: pass
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))
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")
def readParams(): inp, inpRaw = U.doRead() if inp == "": return try: if "debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPImystuff"]) except: pass
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))
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")
def readParams(): global allowedGPIOoutputPins inp,inpRaw = U.doRead() if inp == "": return try: if u"debugRPI" in inp: G.debug= int(inp["debugRPI"]["debugRPIOUTPUT"]) except Exception, e: U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
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))
def readParams(): global allowedGPIOoutputPins inp, inpRaw = U.doRead() if inp == "": return try: if u"debugRPI" in inp: G.debug = int(inp["debugRPI"]["debugRPIOUTPUT"]) except Exception, e: U.toLog( -1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
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))
def readNew(): global fastFreq, fastMute, fastMono, fastScan, fastMinSignal, inp, inpRawOld, newCommand, restart global defFreq, mute, mono, highCut, noiseCancel, bandLimit, DTCon, PLLREF, XTAL, HLSI, devIdFound inpNew, inpRaw = U.doRead(inFile=G.homeDir + G.program + ".set") if inpNew == "": return try: newCommand = True updateF = False updateM = False updateO = False restart = False if u"frequency" in inpNew: fastFreq = float(inpNew["frequency"]) updateF = True if u"mute" in inpNew: fastMute = int(inpNew["mute"]) updateM = True if u"mono" in inpNew: fastMono = int(inpNew["mono"]) updateO = True if u"scan" in inpNew: fastScan = int(inpNew["scan"]) if u"minSignal" in inpNew: fastMinSignal = int(inpNew["minSignal"]) if u"restart" in inpNew: restart = (inpNew["restart"] == "1") if len(unicode(inp)) > 200 and (updateF or updateM or updateO) and fastScan != 1: device = "setTEA5767" if device in inp["output"]: for devId in inp["output"][device]: if updateM: inp["output"][device][devId][0]["mute"] = inpNew[ "mute"] if updateF: inp["output"][device][devId][0]["defFreq"] = inpNew[ "frequency"] if updateO: inp["output"][device][devId][0]["mono"] = inpNew[ "mono"] f = open(G.homeDir + "parameters", "w") f.write(json.dumps(inp, sort_keys=True, indent=2)) f.close() break os.remove(G.homeDir + G.program + ".set") if restart: U.toLog(0, u"restarting radio") time.sleep(0.1) os.system("/usr/bin/python " + G.homeDir + G.program + ".py &") except Exception, e: U.toLog( -1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
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))
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")
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))
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))
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))
def readNew(): global fastFreq, fastMute,fastMono,fastScan,fastMinSignal, inp, inpRawOld, newCommand, restart global defFreq, mute, mono, highCut, noiseCancel, bandLimit, DTCon, PLLREF, XTAL, HLSI, devIdFound inpNew,inpRaw = U.doRead(inFile=G.homeDir+G.program+".set") if inpNew == "": return try: newCommand = True updateF = False updateM = False updateO = False restart = False if u"frequency" in inpNew: fastFreq = float(inpNew["frequency"]) updateF = True if u"mute" in inpNew: fastMute = int(inpNew["mute"]) updateM = True if u"mono" in inpNew: fastMono = int(inpNew["mono"]) updateO = True if u"scan" in inpNew: fastScan = int(inpNew["scan"]) if u"minSignal" in inpNew: fastMinSignal = int(inpNew["minSignal"]) if u"restart" in inpNew: restart = (inpNew["restart"] =="1") if len(unicode(inp))> 200 and (updateF or updateM or updateO) and fastScan !=1: device = "setTEA5767" if device in inp["output"]: for devId in inp["output"][device]: if updateM: inp["output"][device][devId][0]["mute"] = inpNew["mute"] if updateF: inp["output"][device][devId][0]["defFreq"] = inpNew["frequency"] if updateO: inp["output"][device][devId][0]["mono"] = inpNew["mono"] f=open(G.homeDir+"parameters","w") f.write(json.dumps(inp,sort_keys=True, indent=2)) f.close() break os.remove(G.homeDir+G.program+".set") if restart: U.toLog(0, u"restarting radio") time.sleep(0.1) os.system("/usr/bin/python "+G.homeDir+G.program+".py &") except Exception, e: U.toLog(-1, u"in Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
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))
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))
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))
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))
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
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))
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))
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))
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
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])
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])
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])
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
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]
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))
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]
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]))
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()
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
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))
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))
####################### 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))
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()
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]
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))
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)
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()
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
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()
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))
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]
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()
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]) )
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
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))
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))
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]