def __init__(self, adc, adc_multi, voltage_calibration_0, pH_calibration_value_0, voltage_calibration_1, pH_calibration_value_1, precision=2, interval=None, mqtt_topic=None, friendly_name=None, discover=True): # This makes it possible to use multiple instances of MySensor global _unit_index _unit_index += 1 super().__init__(COMPONENT_NAME, __version__, _unit_index, discover) self._interval = interval or config.INTERVAL_SENSOR_PUBLISH self._topic = mqtt_topic self._frn = friendly_name self._adc = ADC(adc) self._adc_multi = adc_multi self.__ph = None self._prec = int(precision) self._v0 = voltage_calibration_0 self._v1 = voltage_calibration_1 self._ph0 = pH_calibration_value_0 self._ph1 = pH_calibration_value_1 gc.collect() if self._interval > 0: # if interval==-1 no loop will be started asyncio.get_event_loop().create_task(self._loop())
def __init__(self, r1, ra, adc, power_pin, ppm_conversion, temp_coef, k, temp_sensor, precision_ec=3, interval=None, topic_ec=None, topic_ppm=None, friendly_name_ec=None, friendly_name_ppm=None): super().__init__() self._interval = interval or config.INTERVAL_SEND_SENSOR self._prec_ec = int(precision_ec) self._adc = ADC(adc) self._ppin = Pin(power_pin, machine.Pin.OUT) self._r1 = r1 self._ra = ra self._ppm_conversion = ppm_conversion self._temp_coef = temp_coef self._k = k self._temp = temp_sensor if hasattr(temp_sensor, "temperature") is False: raise AttributeError( "Temperature sensor {!s}, type {!s} has no async method temperature()".format(temp_sensor, type(temp_sensor))) gc.collect() self._ec25 = None self._ppm = None self._time = 0 # This makes it possible to use multiple instances of MySensor global _count self._count = _count _count += 1 self._topic_ec = topic_ec or _mqtt.getDeviceTopic("{!s}/{!s}".format("EC", self._count)) self._topic_ppm = topic_ppm or _mqtt.getDeviceTopic("{!s}/{!s}".format("PPM", self._count)) self._frn_ec = friendly_name_ec self._frn_ppm = friendly_name_ppm
def __init__(self, adc, voltage_max, voltage_min, multiplier_adc, cutoff_pin=None, precision_voltage=2, interval_watching=1, interval=None, mqtt_topic=None, friendly_name=None, friendly_name_abs=None): super().__init__() self._interval = interval or config.INTERVAL_SEND_SENSOR self._interval_watching = interval_watching self._topic = mqtt_topic or _mqtt.getDeviceTopic(_component_name) self._precision = int(precision_voltage) self._adc = ADC(adc) # unified ADC interface self._voltage_max = voltage_max self._voltage_min = voltage_min self._multiplier = multiplier_adc self._cutoff_pin = None if cutoff_pin is None else (Pin( cutoff_pin, machine.Pin.OUT)) if self._cutoff_pin is not None: self._cutoff_pin.value(0) self._frn = friendly_name self._frn_abs = friendly_name_abs gc.collect() self._event_low = None self._event_high = None
def __init__(self, r1, ra, rg, adc, power_pin, ground_pin, ppm_conversion, temp_coef, k, temp_sensor: ComponentSensor, read_timeout=400, iterations=1, precision_ec=3, friendly_name_ec=None, friendly_name_ppm=None, **kwargs): # This makes it possible to use multiple instances of MySensor global _unit_index _unit_index += 1 self.checkSensorType(temp_sensor, SENSOR_TEMPERATURE) super().__init__(COMPONENT_NAME, __version__, _unit_index, logger=_log, **kwargs) self._temp = temp_sensor self._addSensorType("ec", precision_ec, 0, VALUE_TEMPLATE_JSON.format("ec|float"), "mS", friendly_name_ec or "EC", self._topic, DISCOVERY_EC) self._addSensorType("ppm", 0, 0, VALUE_TEMPLATE_JSON.format("ppm|int"), "ppm", friendly_name_ppm or "PPM", self._topic, DISCOVERY_PPM) self._adc = ADC(adc) self._ppin = Pin(power_pin, machine.Pin.IN) # changing to OUTPUT GND when needed self._gpin = Pin(ground_pin, machine.Pin.IN) # changing to OUTPUT GND when needed self._r1 = r1 self._ra = ra self._rg = rg self._ppm_conversion = ppm_conversion self._temp_coef = temp_coef self._k = k self._to = read_timeout self._iters = iterations gc.collect()
def __init__(self, adc, power_pin=None, cutoff_voltage=None, interval_publish=None, interval_reading=1, mqtt_topic=None, friendly_name=None, discover=True, expose_intervals=False, intervals_topic=None): interval_publish = interval_publish or -1 global _unit_index _unit_index += 1 super().__init__(COMPONENT_NAME, __version__, _unit_index, discover, interval_publish, interval_reading, mqtt_topic, _log, expose_intervals, intervals_topic) self._adc = ADC(adc) self._ppin = Pin(power_pin, machine.Pin.OUT) if power_pin is not None else None self._cv = cutoff_voltage or self._adc.maxVoltage() self._lv = None self._addSensorType(SENSOR_BINARY_MOISTURE, 0, 0, VALUE_TEMPLATE, "", friendly_name, mqtt_topic, None, True) self._pub_coro = None
def __init__(self, adc, power_pin=None, cutoff_voltage=None, interval=None, interval_reading=1, topic=None, friendly_name=None): super().__init__() self._ir = interval_reading self._adc = ADC(adc) self._ppin = Pin(power_pin, machine.Pin.OUT) if power_pin is not None else None self._cv = cutoff_voltage or self._adc.maxVoltage() global _instances _instances.append(self) global _count self._t = topic or _mqtt.getDeviceTopic("waterSensor/{!s}".format(_count)) self._count = _count _count += 1 self._lv = None self._tm = time.ticks_ms() interval = interval or config.INTERVAL_SEND_SENSOR self._int = interval * 1000 self._frn = friendly_name
def __init__(self, adc_pin, water_voltage, air_voltage, sensor_types, power_pin=None, power_warmup=None, publish_converted_value=False, mqtt_topic=None, interval=None, friendly_name=None, friendly_name_cv=None, discover=True): super().__init__(COMPONENT_NAME, __version__, discover) self._adc = ADC(adc_pin) if power_pin is None: self._ppin = None else: if type(power_pin) == list: self._ppin = [] for pin in power_pin: self._ppin.append(Pin(pin, machine.Pin.OUT)) else: self._ppin = Pin(power_pin, machine.Pin.OUT) self._power_warmup = power_warmup or None if power_pin is None else 10 self._sensor_types = sensor_types if isinstance( self._adc, pyADC ): # pyADC provides unified single ADC interface, not AMUX raise TypeError("Single ADC (no Amux) can't have multiple sensors") self._water_v = water_voltage self._air_v = air_voltage if type(sensor_types) == list: if type(water_voltage) != list or type(air_voltage) != list: raise TypeError( "Voltages have to be lists with multiple sensor_types") self._pub_cv = publish_converted_value self._topic = mqtt_topic self._interval = interval or config.INTERVAL_SENSOR_PUBLISH self._lock = Lock() self._frn = friendly_name self._frn_cv = friendly_name_cv gc.collect() asyncio.get_event_loop().create_task(self._loop())
def __init__(self, s0, s1, s2, s3=None, mux=None, sig=None, return_voltages=False): """ It is possibile to initialize with: - pin numbers (or string on esp8266) - mux object and pin numbers (of mux pins) - Pin objects (either from machine or mux Pin objects [no mux object needed]) :type return_voltages: bool, True returns voltages on .read() else raw adc value :type mux: Mux object if a multiplexer is used :type sig: ADC pin number (esp32) or None (esp8266) Amux uses default return values of ADC in .read() --> On esp8266 raw, on esp32_LoBo voltage s3 is optional, only needed if 16 pins are used, 8 pins possible with s0-s2. Amux can be read like a list: value=amux[2] """ if mux: self.s0 = s0 self.s1 = s1 self.s2 = s2 self.s3 = s3 self.mux = mux else: if type(s0) in (int, str): self.s0 = Pin(s0 if type(s0) != str else config.pins[s0], Pin.OUT) self.s1 = Pin(s1 if type(s1) != str else config.pins[s1], Pin.OUT) self.s2 = Pin(s2 if type(s2) != str else config.pins[s2], Pin.OUT) if s3: self.s3 = Pin(s3 if type(s3) != str else config.pins[s3], Pin.OUT) else: self.s0 = s0 self.s1 = s1 self.s2 = s2 if s3: self.s3 = s3 if s3: self.__size = 16 else: self.__size = 8 self._return_voltages = return_voltages self.sig = ADC(0 if sig is None and platform == "esp8266" else sig) # unified ADC interface
def __init__(self, adc, voltage_max: float, voltage_min: float, multiplier_adc: float, cutoff_pin=None, precision_voltage: int = 2, interval_reading: float = 1, interval_publish: float = None, mqtt_topic: str = None, friendly_name: str = None, friendly_name_abs: str = None, discover: bool = True, expose_intervals: bool = False, intervals_topic: str = None): global _unit_index _unit_index += 1 super().__init__(COMPONENT_NAME, __version__, _unit_index, discover, interval_publish, interval_reading, mqtt_topic, _log, expose_intervals, intervals_topic) self._adc = ADC(adc) # unified ADC interface self._voltage_max = voltage_max self._voltage_min = voltage_min self._multiplier = multiplier_adc self._cutoff_pin = None if cutoff_pin is None else (Pin(cutoff_pin, machine.Pin.OUT)) if self._cutoff_pin is not None: self._cutoff_pin.value(0) self._event_low = None self._event_high = None self._addSensorType(SENSOR_BATTERY, 2, 0, _VAL_T_CHARGE, "%", friendly_name_abs) self._addSensorType("voltage", precision_voltage, 0, _VAL_T_VOLTAGE, "V", friendly_name, None, _TYPE_VOLTAGE) asyncio.get_event_loop().create_task(self._events()) gc.collect()
def __init__(self, adc, power_pin=None, cutoff_voltage=None, interval_reading=1, friendly_name=None, **kwargs): global _unit_index _unit_index += 1 super().__init__(COMPONENT_NAME, __version__, _unit_index, logger=_log, interval_reading=interval_reading, interval_publish=-1, **kwargs) self._adc = ADC(adc) self._ppin = Pin(power_pin, machine.Pin.OUT) if power_pin is not None else None self._cv = cutoff_voltage or self._adc.maxVoltage() self._lv = None self._addSensorType(SENSOR_BINARY_MOISTURE, 0, 0, VALUE_TEMPLATE, "", friendly_name, self._topic, None, True) self._pub_task = None
def ADC(self, i, *args, **kwargs): """ compatible to machine.ADC, returns an ADC object""" return ADC(self, i)