def timer_ten_per_second(self): if self.initialized and self.enabled: try: val = self.pcf.readpin(self.rpin) if float(val) != float(self.uservar[0]): self.set_value(1, val, True) self._lastdataservetime = rpieTime.millis() except: pass return self.timer100ms
def plugin_read(self): result = False if self.enabled: if len(self.TARR)>0 and len(self.HARR)>0: try: self.set_value(1,self.TARR[-1],False) self.set_value(2,self.HARR[-1],False) self.plugin_senddata() self._lastdataservetime = rpieTime.millis() self._nextdataservetime = self._lastdataservetime + (self.interval*1000) - self.preread self.failures = 0 except: pass if self.interval>10: self.disconnect() self.TARR = [] self.HARR = [] elif (self._nextdataservetime < rpieTime.millis()): self.isconnected()
def timer_once_per_second(self): if self.enabled: if self._nextdataservetime - rpieTime.millis() <= self.preread: if self.conninprogress == False and self.connected == False: self.waitnotifications = False if len(self.taskdevicepluginconfig[0]) > 10: self.cproc = threading.Thread(target=self.connectproc) self.cproc.daemon = True self.cproc.start() return self.timer1s
def p003_handler(self, channel): if (self.irqinprogress == False): self.irqinprogress = True atime = rpieTime.millis() ptime = atime - self.pulsetimeprevious if (ptime > int(self.taskdevicepluginconfig[0])): self.pulsecounter += 1 self.pulsetotalcounter += 1 self.pulsetime = ptime self.pulsetimeprevious = atime self.irqinprogress = False
def plugin_read( self): # deal with data processing at specified time interval result = False if self.initialized and self.readinprogress == 0 and self.enabled: self.readinprogress = 1 atemp = self.read_lm75() self.set_value(1, atemp, True) self._lastdataservetime = rpieTime.millis() result = True self.readinprogress = 0 return result
def plugin_read(self): # deal with data processing at specified time interval result = False if self.initialized: for x in range(self.valuecount): if len(self.formula[x])>1 and ("%" in self.formula[x]) and ("value" not in self.formula[x].lower()): self.uservar[x] = commands.parsevalue(self.formula[x]) logs = self.gettaskname()+"#"+self.valuenames[x]+"="+str(misc.formatnum(self.uservar[x],self.decimals[x])) misc.addLog(rpieGlobals.LOG_LEVEL_INFO,logs) self._lastdataservetime = rpieTime.millis() self.plugin_senddata() result = True return result
def plugin_init(self, enableplugin=None): plugin.PluginProto.plugin_init(self, enableplugin) self.readinprogress = False self.connected = False self.conninprogress = False self.waitnotifications = False self.lastrequest = 0 self.TARR = [] self.HARR = [] try: if self.preread: pass except: self.preread = 4000 self.uservar[0] = 0 self.uservar[1] = 0 if self.enabled: self.ports = str(self.taskdevicepluginconfig[0]) self.timer1s = True self.battery = -1 self._nextdataservetime = rpieTime.millis() - self.preread self._lastdataservetime = 0 # self.lastread = 0 self.failures = 0 self._lastdataservetime = rpieTime.millis() - ( (self.interval - 2) * 1000) if self.taskdevicepluginconfig[1]: self.valuecount = 3 self.vtype = rpieGlobals.SENSOR_TYPE_TRIPLE else: self.valuecount = 2 self.vtype = rpieGlobals.SENSOR_TYPE_TEMP_HUM try: devnum = int(self.taskdevicepluginconfig[2]) self.blestatus = BLEHelper.BLEStatus[devnum] except: pass else: self.ports = "" self.timer1s = False
def plugin_init(self, enableplugin=None): initok = False self.readinprogress = False if self.enabled: if self.taskdevicepin[0] >= 0: try: gpios.HWPorts.add_event_detect(self.taskdevicepin[0], gpios.FALLING, self.p064_handler, 200) self.timer100ms = False except Exception as e: if str(self.taskdevicepluginconfig[0]) == "0": self.timer100ms = True misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, "Interrupt error " + str(e)) else: if str(self.taskdevicepluginconfig[0]) == "0": self.timer100ms = True try: i2cok = gpios.HWPorts.i2c_init() if i2cok: if self.interval > 2: nextr = self.interval - 2 else: nextr = self.interval self.apds = APDS9960(gpios.HWPorts.i2cbus) self._lastdataservetime = rpieTime.millis() - (nextr * 1000) self.lastread = 0 initok = True else: self.enabled = False misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, "I2C can not be initialized!") except Exception as e: self.enabled = False misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, "APDS init error " + str(e)) if initok: try: self.apds.setProximityIntLowThreshold(50) if str(self.taskdevicepluginconfig[0]) == "1": self.apds.enableProximitySensor() self.apds.enableLightSensor() else: self.apds.enableGestureSensor() except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, "APDS setup error " + str(e)) plugin.PluginProto.plugin_init(self, enableplugin) self.initialized = initok
def plugin_read( self): # deal with data processing at specified time interval result = False if self.initialized and self.readinprogress == 0 and self.enabled: self.readinprogress = 1 temp, press = self.bmp.get_data() self.set_value(1, temp, False) self.set_value(2, press, False) self.plugin_senddata() self._lastdataservetime = rpieTime.millis() result = True self.readinprogress = 0 return result
def plugin_init(self,enableplugin=None): plugin.PluginProto.plugin_init(self,enableplugin) self.TARR = [] self.HARR = [] self.uservar[0] = 0 self.uservar[1] = 0 if self.enabled: if self.interval>2: nextr = self.interval-2 else: nextr = 0 self._lastdataservetime = rpieTime.millis()-(nextr*1000) self.lastread = 0
def p062_handler(self, pin): if self.initialized and self.enabled and self.readinprogress == 0: try: self.readinprogress = 1 key = self.mpr.readTouch() if key > 0: if self.taskdevicepluginconfig[1] == False: key = self.mpr.get_key_map(key) self.set_value(1, key, True) self._lastdataservetime = rpieTime.millis() except Exception as e: pass self.readinprogress = 0
def plugin_read(self): # Doing periodic status reporting res = False if self.initialized and self.enabled: try: vusb.usbrelay.initdevifneeded(self.taskdevicepluginconfig[0]) swval = vusb.usbrelay.state(int(self.taskdevicepluginconfig[1])) res = True except: swval = 0 res = False self.set_value(1,int(swval),True) self._lastdataservetime = rpieTime.millis() return res
def plugin_read(self): # deal with data processing at specified time interval result = False if self.initialized and self.enabled and self.readinprogress==0: self.readinprogress = 1 try: result = self.mcp.input(self.rpin) self.set_value(1,result,True) self._lastdataservetime = rpieTime.millis() except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,str(e)) self.readinprogress = 0 result = True return result
def plugin_read( self): # deal with data processing at specified time interval result = False if self.initialized and self.enabled: val = self.mcp_get_value() if val != -1: self.set_value(1, val, False) self.plugin_senddata() result = True self._lastdataservetime = rpieTime.millis() self._nextdataservetime = self._lastdataservetime + ( self.interval * 1000) return result
def plugin_read( self): # deal with data processing at specified time interval result = False if self.initialized and self.readinprogress == 0: self.readinprogress = 1 for v in range(0, 4): vtype = int(self.taskdevicepluginconfig[v]) if vtype != 0: self.set_value(v + 1, self.p026_get_value(vtype), False) self.plugin_senddata() self._lastdataservetime = rpieTime.millis() result = True self.readinprogress = 0 return result
def plugin_read(self): result = False if self.initialized and self.readinprogress == 0: self.readinprogress = 1 if self.validloc == 1: self.set_value(1, self.lon, False) self.set_value(2, self.lat, False) self.set_value(3, self.GPSDAT['alt'], False) self.set_value(4, self.GPSTRACK['speedKm'], False) self.plugin_senddata() self._lastdataservetime = rpieTime.millis() result = True self.readinprogress = 0 return result
def plugin_read(self): # deal with data processing at specified time interval result = False if self.initialized and self.enabled: self.p025_get_value() if len(self.TARR)>0: self.set_value(1,(sum(self.TARR) / float(len(self.TARR))),False) self.plugin_senddata() else: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"ADS1x15 read failed!") result = True self.TARR = [] self._lastdataservetime = rpieTime.millis() self._nextdataservetime = self._lastdataservetime + (self.interval*1000) return result
def plugin_read(self): result = False if self.enabled: if len(self.TARR) > 0 and len(self.HARR) > 0: self.get_battery_value() if self.battery == -1: self.get_battery_value() if self.battery == -1: self.get_battery_value() try: self.set_value(1, self.TARR[-1], False) if self.taskdevicepluginconfig[1]: self.set_value(2, self.HARR[-1], False) self.set_value(3, self.battery, False, susebattery=self.battery) else: self.set_value(2, self.HARR[-1], False, susebattery=self.battery) self.plugin_senddata(pusebattery=self.battery) self._lastdataservetime = rpieTime.millis() self._nextdataservetime = self._lastdataservetime + ( self.interval * 1000) self.failures = 0 except: pass if self.interval > 10: self.disconnect() self.TARR = [] self.HARR = [] elif (self._nextdataservetime < rpieTime.millis()): self._nextdataservetime = self._lastdataservetime + uniform( self.preread, self.preread * 2.5) self.isconnected()
def connectproc(self): try: if self.blestatus.isscaninprogress(): self.blestatus.requeststopscan(self.taskindex) return False except Exception as e: return False self.conninprogress = True while self.blestatus.norequesters( ) == False or self.blestatus.nodataflows() == False: time.sleep(0.5) misc.addLog( rpieGlobals.LOG_LEVEL_DEBUG_MORE, "BLE line not free for P512! " + str(self.blestatus.dataflow)) self.blestatus.registerdataprogress(self.taskindex) prevstate = self.connected try: misc.addLog( rpieGlobals.LOG_LEVEL_DEBUG, "BLE connection initiated to " + str(self.taskdevicepluginconfig[0])) time.sleep(uniform(0.4, 1.8)) self.BLEPeripheral = btle.Peripheral( str(self.taskdevicepluginconfig[0]), iface=self.taskdevicepluginconfig[2]) self.connected = True self.failures = 0 self.BLEPeripheral.setDelegate(TempHumDelegate(self.callbackfunc)) except: self.connected = False self.conninprogress = False self.isconnected() if self.connected == False: misc.addLog( rpieGlobals.LOG_LEVEL_ERROR, "BLE connection failed " + str(self.taskdevicepluginconfig[0])) self.blestatus.unregisterdataprogress(self.taskindex) self.failures = self.failures + 1 if self.failures > 5: self._nextdataservetime = rpieTime.millis() + (self.interval * 5000) self._lastdataservetime = self._nextdataservetime return False else: misc.addLog( rpieGlobals.LOG_LEVEL_DEBUG, "BLE connected to " + str(self.taskdevicepluginconfig[0])) self.waitnotifications = True self.get_battery_value() rpieTime.addsystemtimer(3, self.isconnected, [-1])
def plugin_read(self): # deal with data processing at specified time interval result = False if self.enabled and self.initialized and self.readinprogress==0: self.readinprogress = 1 try: val1 = self.read_max44009() except Exception as e: val1 = None misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"MAX44009: "+str(e)) if val1 is not None: self.set_value(1,val1,True) self._lastdataservetime = rpieTime.millis() result = True self.readinprogress = 0 return result
def timer_ten_per_second(self): if self.initialized and self.enabled: v1 = gpios.HWPorts.input(self.taskdevicepin[0]) v2 = gpios.HWPorts.input(self.taskdevicepin[1]) if (v1 == 1) and (v2 == 1): self.actualstate = 1 if (v1 == 0) and (v2 == 0): self.actualstate = 0 if float(self.actualstate) != float(self.laststate): self.set_value(1, self.actualstate, True) self.laststate = self.actualstate self._lastdataservetime = rpieTime.millis() if int(float(self.uservar[1])) != int(v1): self.set_value(2, v1, False) if int(float(self.uservar[2])) != int(v2): self.set_value(3, v2, False)
def plugin_init(self, enableplugin=None): plugin.PluginProto.plugin_init(self, enableplugin) self.readinprogress = 0 if self.enabled: try: self.thermostat = Thermostat( str(self.taskdevicepluginconfig[0])) self.initialized = True time.sleep(1) except: self.initialized = False if self.interval > 2: nextr = self.interval - 2 else: nextr = 0 self._lastdataservetime = rpieTime.millis() - (nextr * 1000)
def plugin_read( self): # deal with data processing at specified time interval result = False if self.initialized and self.enabled and self.readinprogress == 0: self.readinprogress = 1 try: pt = int(self.taskdevicepluginconfig[1]) pn = int(self.taskdevicepluginconfig[2]) readcmd = self.create_read_buffer(pt, pn) except Exception as e: return False pmeid = self.pme.beginTransmission(pn, True) if pmeid != 0: try: self.pme.write(readcmd, pmeid) # send read data command if pt == 0: time.sleep(0.001) # digital read is almost instantous else: time.sleep(0.01) # analog read takes more time data = self.pme.read(4, pmeid) # read data if len(data) > 3: if data[2] == data[3] and data[3] == 255: if self.sketch == 0: misc.addLog( rpieGlobals.LOG_LEVEL_ERROR, "ProMini I2C frozen, restart it manually and consider using new sketch!" ) data = [] self.pme.endTransmission(pmeid) result = 0 if len(data) > 0: if pt == 0: result = int(data[0]) if result not in [ 0, 1 ]: # invalid value,digital can only be 0 or 1! return False elif len(data) > 1: result = (data[1] << 8 | data[0]) # 0-1023 self.set_value(1, result, True) self._lastdataservetime = rpieTime.millis() except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, str(e)) self.readinprogress = 0 result = True return result
def plugin_init(self, enableplugin=None): plugin.PluginProto.plugin_init(self, enableplugin) self.uservar[0] = 0 self.uservar[1] = 0 self.uservar[2] = 0 sensoraddress = int(self.taskdevicepluginconfig[0]) if self.enabled and sensoraddress in [0x76, 0x77]: try: self.bme = None try: i2cl = self.i2c except: i2cl = -1 i2cbus = gpios.HWPorts.i2c_init(i2cl) if i2cl == -1: i2cbus = gpios.HWPorts.i2cbus self.bme = Bme280(i2c_bus=i2cbus, sensor_address=sensoraddress) if (self.bme is not None) and (i2cbus is not None) and self.bme.init: if self.interval > 2: nextr = self.interval - 2 else: nextr = self.interval self._lastdataservetime = rpieTime.millis() - (nextr * 1000) else: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, "BME through I2C can not be initialized!") self.initialized = False except Exception as e: misc.addLog(rpieGlobals.LOG_LEVEL_ERROR, str(e)) self.initialized = False if self.enabled: chiptype = self.bme.get_chip_id() self.hashumidity = False chipname = "Unknown" if chiptype == 0x60: chipname = "BME280" self.hashumidity = True self.vtype = rpieGlobals.SENSOR_TYPE_TEMP_HUM_BARO elif chiptype in [0x56, 0x57, 0x58]: chipname = "BMP280" self.vtype = rpieGlobals.SENSOR_TYPE_TEMP_EMPTY_BARO misc.addLog( rpieGlobals.LOG_LEVEL_INFO, chipname + " (" + str(chiptype) + ") initialized, Humidity: " + str(self.hashumidity))
def timer_ten_per_second(self): if self.enabled and self.initialized: changed = False if time.time()-self.thermtime > 1: self.therm = self.amg.readThermistor() self.thermtime=time.time() self.readdata() for i in range(0,4): val = int(self.taskdevicepluginconfig[i+1]) if val>0: if abs(float(self.uservar[i])-float(self.getvalue(val)))>=0.2: self.set_value(i+1,self.getvalue(val),False) changed = True if changed: self._lastdataservetime = rpieTime.millis() self.plugin_senddata() return self.timer100ms
def plugin_read(self): # deal with data processing at specified time interval result = False if self.enabled and self.initialized: try: self.therm = self.amg.readThermistor() self.readdata() for i in range(0,4): val = int(self.taskdevicepluginconfig[i+1]) if val>0: self.set_value(i+1,self.getvalue(val),False) result = True except Exception as e: print(e) if result: self._lastdataservetime = rpieTime.millis() self.plugin_senddata() return result
def p059_handler(self, channel): if self.initialized and self.enabled: aclk = gpios.HWPorts.input(self.taskdevicepin[0]) if aclk != self.clklast: dtstate = gpios.HWPorts.input(self.taskdevicepin[1]) try: ac = float(self.uservar[0]) except: ac = 0 if dtstate != aclk: if ac < int(self.taskdevicepluginconfig[2]): ac += int(self.taskdevicepluginconfig[0]) else: if ac > int(self.taskdevicepluginconfig[1]): ac -= int(self.taskdevicepluginconfig[0]) self.clklast = aclk self.set_value(1, ac, True) self._lastdataservetime = rpieTime.millis()
def plugin_read(self): # deal with data processing at specified time interval result = False if self.enabled and self.initialized and self.readinprogress==0: self.readinprogress = 1 try: if str(self.taskdevicepluginconfig[1]) == "6": val1 = self.mlx.get_amb_temp() else: val1 = self.mlx.get_obj_temp() except Exception as e: val1 = None misc.addLog(rpieGlobals.LOG_LEVEL_ERROR,"MLX90614: "+str(e)) if val1 is not None: self.set_value(1,val1,True) self._lastdataservetime = rpieTime.millis() result = True self.readinprogress = 0 return result
def plugin_read( self): # deal with data processing at specified time interval result = False if self.initialized and self.readinprogress == 0 and self.enabled: self.readinprogress = 1 try: batt = self.flora.battery_level() except: batt = 100 for v in range(0, 4): vtype = int(self.taskdevicepluginconfig[v + 1]) if vtype != 0: self.set_value(v + 1, self.p515_get_value(vtype), False) self.plugin_senddata(pusebattery=batt) self._lastdataservetime = rpieTime.millis() result = True self.readinprogress = 0 return result
def plugin_read(self): result = False if self.initialized and self.enabled and self.readinprogress==False and (self.adc is not None): self.readinprogress = True try: if self.taskdevicepluginconfig[0] == 0: self.set_value(1,self.adc.analog_read(),False) elif self.taskdevicepluginconfig[0] == 1: self.set_value(1,self.adc.read_resistance(),False) elif self.taskdevicepluginconfig[0] == 2: self.set_value(1,self.adc.read_temp_c(self.taskdevicepluginconfig[5],self.taskdevicepluginconfig[4]),False) except: pass self.plugin_senddata() self._lastdataservetime = rpieTime.millis() self.readinprogress = False result = True return result