Пример #1
0
def read_temperatures(ds: ds18x20.DS18X20) -> dict:
    values = {}
    roms = ds.scan()  # scan for sensors on the bus
    ds.convert_temp()  # read temps in °C - need to wait for 750ms
    time.sleep_ms(750)

    for rom in roms:
        serialnum = rom2str(rom)
        values[serialnum] = ds.read_temp(rom)
    return values
Пример #2
0
def temp_init(pin=PIN_TEMP):
    printHead("temp")
    print("dallas temp init >")
    from onewire import OneWire
    from ds18x20 import DS18X20
    dspin = Pin(pin)
    # from util.octopus_lib import bytearrayToHexString
    try:
        ds = DS18X20(OneWire(dspin))
        ts = ds.scan()

        if len(ts) <= 0:
            io_conf['temp'] = False

        for t in ts:
            print(" --{0}".format(bytearrayToHexString(t)))
    except:
        io_conf['temp'] = False
        print("Err.temp")

    print("Found {0} dallas sensors, temp active: {1}".format(
        len(ts), io_conf.get('temp')))

    if len(ts) > 1:
        print(get_temp_n(ds, ts))
    else:
        print(get_temp(ds, ts))

    return ds, ts
 def __init__(self):
     printflush("Init")
     self.unhandled_event = False
     printflush('Init LEDs')
     self.leds = {
         'red': Pin(D2, Pin.OUT, value=False),
         'blue': Pin(D3, Pin.OUT, value=False),
         'green': Pin(D4, Pin.OUT, value=False)
     }
     printflush('Init OneWire')
     self.ds_pin = Pin(D1)
     self.ow_inst = OneWire(self.ds_pin)
     self.ds_sensor = DS18X20(self.ow_inst)
     self.temp_id = self.ds_sensor.scan()[0]
     printflush('Temperature sensor: %s' % self.temp_id)
     printflush('set LED red')
     self.leds['red'].on()
     printflush('Instantiate WLAN')
     self.wlan = network.WLAN(network.STA_IF)
     printflush('connect_wlan()')
     self.connect_wlan()
     printflush('turn off red LED')
     self.leds['red'].off()
     printflush('hexlify mac')
     self.mac = hexlify(self.wlan.config('mac')).decode()
     printflush('MAC: %s' % self.mac)
     self.entity_id = ENTITIES[self.mac]
     self.friendly_name = FRIENDLY_NAMES[self.mac]
     printflush('Entity ID: %s; Friendly Name: %s' % (
         self.entity_id, self.friendly_name
     ))
     self.post_path = '/api/states/' + self.entity_id
     printflush('POST path: %s' % self.post_path)
Пример #4
0
    def __init__(self, internal_sensor_pin, external_sensor_pin):
        self.internal_sensor = DS18X20(OneWire(internal_sensor_pin))

        # scan for devices on the bus
        self.rom = self.internal_sensor.scan()[0]

        self.external_sensor = DHT11(external_sensor_pin)
Пример #5
0
    def __init__(self):
        p_pwr1.value(1)

        ow = OneWire(p_DS18B20)  # Pin 13 is the data pin for the DS18B20
        self.ds = DS18X20(ow)  # Initialize a ds18b20 object
        self.roms = self.ds.scan(
        )  # Find all the DS18B20 sensors that are attached (we only have one)
Пример #6
0
 def __init__(self, pin: int, pause: int = 1, verbose: bool = False):
     self._pin = pin
     self._temperature_sensor = DS18X20(OneWire(Pin(pin)))
     self._temperature_chips = self._temperature_sensor.scan()
     self.pause = pause
     self.is_verbose = verbose
     self.state = dict(temperature=dict())
     print("The sensor controller module started")
Пример #7
0
 def __init__(self, postfix, pin, **kwargs):
     super().__init__(postfix, **kwargs)
     self.pin = Pin(pin)
     self.onewire = OneWire(self.pin)
     self.sensor = DS18X20(self.onewire)
     self.roms = self.sensor.scan()
     self.initialized = False  # Sensor conversion takes 700mS, always lag one iteration behind.
     print("Found %d ds18x20 sensor(s)" % len(self.roms))
Пример #8
0
    def __prep_pin(self, pin):
        """Prepare pin for OneWire device

        Args:
            pin (int): pin with onewire device
        """
        self.ds = DS18X20(OneWire(Pin(pin)))
        self.dev = self.ds.scan()[0]
Пример #9
0
    def __init__(self, unit='C'):

        pin = machine.Pin(18)
        o = OneWire(pin)

        self.d = DS18X20(o)
        self.devicelist = self.d.scan()
        self.unit = unit
 def __init__(self, pin):
     """
     Finds addresses of DS18B20 on bus specified by `pin`
     :param pin: 1-Wire bus pin
     :type pin: int
     """
     self.ds = DS18X20(OneWire(Pin(pin)))
     self.addrs = self.ds.scan()
     if not self.addrs:
         raise Exception('no DS18B20 found at bus on pin %d' % pin)
Пример #11
0
    def __init__(self):
        from machine import Pin
        from ds18x20 import DS18X20
        import onewire
        import time
        
        # the device is on GPIO12
        self.dat = Pin(12)

        # create the onewire object
        self.ds = DS18X20(onewire.OneWire(self.dat))
Пример #12
0
 def __init__(self, pin):
     if not isinstance(pin, int):
         raise TypeError("pin must be integer")
     from onewire import OneWire
     from ds18x20 import DS18X20
     ow = OneWire(machine.Pin(pin))
     ow.scan()
     ow.reset()
     self.ds18b20 = DS18X20(ow)
     self.roms = self.ds18b20.scan()
     self.temps = [None for rom in self.roms]
Пример #13
0
    def __init__(self, pin):
        self.check_ticks_ms = 0
        self.ds = DS18X20(OneWire(Pin(pin)))
        self.rom = None
        self.buffer = RingBuffer(6)
        self.state = DS_IDEL

        roms = self.ds.scan()
        if roms:
            self.rom = roms[0]
            UI.LogOut(str(self.rom))
Пример #14
0
    def __init__(self, channel_id, api_key, pin):
        self.channel_id = channel_id
        self.api_key = api_key
        self.ds = DS18X20(OneWire(pin))
        self.sensor = first(self.ds.scan())

        if self.sensor is None:
            raise BrewtrackerError("No temperature sensor available!")

        # Last read sensor value in degrees celsius
        self.value = 0
Пример #15
0
    def __init__(self, pin=32):
        from onewire import OneWire
        from ds18x20 import DS18X20

        self.pin = pin
        self.ts = []
        try:
            self.ds = DS18X20(OneWire(Pin(self.pin)))
            self.ts = self.ds.scan()
        except Exception:
            print("Found {0} dallas sensors, temp active: {1}".format(len(ts), io_conf.get('temp')))
Пример #16
0
    def __init__(self, ow_pin, fan_pin):
        ow = OneWire(ow_pin)
        self.ds_sensor = DS18X20(ow)
        self.roms = []

        fan_pin.value(0)
        self.fan_pin = fan_pin
        self.fan_value = 'off'

        self.acc = 0
        self.acc_count = 0
Пример #17
0
 def __init__(self, pin):
     """Finds address of single DS18B20 on bus specified by `pin`
     Args:
         pin: 1-Wire bus pin
     """
     self.ds = DS18X20(OneWire(Pin(pin)))
     addrs = self.ds.scan()
     if not addrs:
         raise Exception('no DS18B20 found at bus on pin %d' % pin)
     # save what should be the only address found
     self.addr = addrs.pop()
Пример #18
0
    def __init__(self, config={}):
        self._temp_sens = DS18X20(OneWire(Pin(config.get("pin", 0))))
        self._temp_sens_dev = self._temp_sens.scan()[0]
        self.last_read = time()
        self.state = None
        self.old_state = None

        self.type = config.get('type', "temp_sensor")
        self.topic = config.get('state_topic', None)
        self.set_topic = config.get('command_topic', None)

        self._temp_sens.convert_temp()
Пример #19
0
 def __init__(self, pin):
     """
     Finds address of single DS18B20 on bus specified by `pin`
     :param pin: 1-Wire bus pin
     :type pin: int
     """
     self.ds = DS18X20(OneWire(Pin(pin)))
     addrs = self.ds.scan()
     if not addrs:
         raise Exception('no DS18B20 found at bus on pin %d' % pin)
     # save what should be the only address found
     self.addr = addrs.pop()
     print("found one sensor at address:", self.addr)
Пример #20
0
 def register_sensor(self):
     if self.pin > 16 or self.pin < 0:
         raise Exception('Invalid GPIO {}'.format(self.pin))
     if self.sensor_model == "DHT11":
         self.sensor_handle = dht.DHT11(Pin(self.pin))
     elif self.sensor_model == "DHT22":
         self.sensor_handle = dht.DHT22(Pin(self.pin))
     elif self.sensor_model == 'DS18B20':
         self.sensor_handle = DS18X20(OneWire(self.pin))
         self.sensor_handle.convert_temp()
     elif self.sensor_model == 'SWITCH':
         self.sensor_handle = Pin(self.pin, Pin.IN, Pin.PULL_UP)
     return True
Пример #21
0
    def __init__(self, motion_pin, micro_pin, pixel_pin, pixels, temp_pin):
        self.motion = 'OFF'
        self.motion_timer = Timer(-1)
        self.temp_timer = Timer(-2)
        self.temperature = None
        self.one_wire = DS18X20(OneWire(Pin(temp_pin)))
        self.temp_sensor = None  # initiated in function temp_sensor
        self.micro_sensor = Pin(micro_pin, Pin.IN)
        self.micro_sensor.irq(handler=self.micro_high, trigger=Pin.IRQ_RISING)
        self.motion_sensor = Pin(motion_pin, Pin.IN)
        self.motion_sensor.irq(handler=self.motion_high,
                               trigger=Pin.IRQ_RISING)
        self.pixels = NeoPixel(Pin(pixel_pin), pixels)
        self.lastmotion = time()

        self.temp_sensor_init()
Пример #22
0
def Get(aPin, aID):
    Pin = machine.Pin(aPin)
    W1  = onewire.OneWire(Pin)
    Obj = DS18X20(W1)

    R = []
    if (not aID): 
        #Roms = W1.scan() # hangs if no devices
        aID = Obj.scan()

    Obj.convert_temp()
    time.sleep_ms(750)
    for ID in aID:
        Value = Obj.read_temp(ID) 
        R.append(Value)
    return R
Пример #23
0
def get_data_ds18b20(pin_nr):
    ds_pin = machine.Pin(pin_nr)
    ds_sensor = DS18X20(OneWire(ds_pin))

    roms = ds_sensor.scan()

    if not roms:
        return None

    ds_sensor.convert_temp()
    utime.sleep_ms(750)  # give enough time to convert the temperature

    temperature = None

    for rom in roms:
        temperature = ds_sensor.read_temp(rom)

    return {'temperature': temperature, 'humidity': None}
 def __init__(self):
     print("Init")
     self.unhandled_event = False
     print('Init LEDs')
     self.leds = {
         'red': Pin(D2, Pin.OUT, value=False),
         'blue': Pin(D3, Pin.OUT, value=False),
         'green': Pin(D4, Pin.OUT, value=False)
     }
     print('Init OneWire')
     self.ds_pin = Pin(D1)
     self.ow_inst = OneWire(self.ds_pin)
     self.ds_sensor = DS18X20(self.ow_inst)
     self.temp_id = self.ds_sensor.scan()[0]
     print('Temperature sensor: %s' % self.temp_id)
     self.wlan = network.WLAN(network.STA_IF)
     self.mac = hexlify(self.wlan.config('mac')).decode()
     print('MAC: %s' % self.mac)
Пример #25
0
    def __init__(self, name="One Wire DS18B20", pin=12, interval=10, pull=-1):
        super().__init__(id="ds18b20", name=name, type="ds18b20")
        self.ds18b20 = DS18X20(OneWire(Pin(pin)))
        addrs = self.ds18b20.scan()
        if not addrs:
            raise Exception("no DS18B20 found at bus on pin %d" % pin)
        # save what should be the only address found
        self.addr = addrs.pop()
        self.interval = interval

        self.p_temp = HomieProperty(
            id="temperature",
            name="Temperature",
            datatype=FLOAT,
            format="-40:80",
            unit="°F",
            default=0,
        )
        self.add_property(self.p_temp)

        asyncio.create_task(self.update_data())
Пример #26
0
def main():
    connect_to_wifi(SSID, PASSWORD)

    print('Initial delay ...')
    sleep(5)

    pin = machine.Pin(PIN)
    ow = DS18X20(onewire.OneWire(pin))

    sensors = ow.scan()

    if not sensors:
        print('Cannot find any OneWire sensor')
        return

    print('Sensors found:', sensors)

    while True:
        for sensor in sensors:
            # Measuring
            try:
                ow.convert_temp()
                sleep(1)
                temp = ow.read_temp(sensor)
            except Exception as e:
                print('ERROR while reading from OneWire')
                print(e)

            print('Measured temperature is:', temp)

            # Sending to MQTT
            try:
                print('Sending message to MQTT')
                pub_message(SERVER_IP, TOPIC, b'{}'.format(temp))
            except Exception as e:
                print('ERROR while publishing message to MQTT')
                print(e)

        print('Going to sleep ...')
        sleep(60)
Пример #27
0
    def init_name(self, config):
        self.pin = Component.board.get_pin(self.name)
        self.ds = DS18X20(OneWire(self.pin))
        addresses = self.ds.scan()
        self.sensors = []

        read_all_sensors = ("ids" in config) or ("temperatures" in config)

        for address in addresses:
            hex_address = Sensor.to_hex_address(address)
            signal_name = None

            if hex_address in config:
                sensor = Sensor(address, self, config.pop(hex_address))
                self.sensors.append(sensor)
            elif read_all_sensors:
                sensor = Sensor(address, self, None)
                self.sensors.append(sensor)

        ct.print_info("Found {} DS18x20 sensors.".format(len(self.sensors)))
        ct.print_debug("\n".join(str(x) for x in self.sensors))
        self.countdown = self.interval = -1
Пример #28
0
    def sense(self):
        print('Temperature Sensing and Reporting via MQtt')

        client = MQTTClient("beersense", "mqtt.dynamicdevices.co.uk", port=1883)
        client.connect()

        client.publish("sensors/brewing/status/1", "Running")

        d=DS18X20(Pin('G17', mode=Pin.OUT))

        while(1):
            result=d.read_temps()
            if(len(result) == 0):
                print("Error Reading from DS18X20")
                client.publish("sensors/brewing/status/1", "Sensor Error")
            else:
                if(result[0] > 100.0):
                    print("Temp: Read Error")
                    client.publish("sensors/brewing/status/1", "Sensor Error")
                else:
                    print("Temp: " + str(result[0]) + " C")
                    client.publish("sensors/brewing/temp/1", str(result[0]))
            time.sleep(10)
Пример #29
0
    def __init__(self, name="One Wire DS18B20", pin=12, interval=10, pull=-1):
        super().__init__(id="ds18b20", name=name, type="ds18b20")
        self.ds18b20 = DS18X20(OneWire(Pin(pin)))
        addrs = self.ds18b20.scan()
        if not addrs:
            raise Exception('no DS18B20 found at bus on pin %d' % pin)
        # save what should be the only address found
        self.addr = addrs.pop()

        self.temperature = 0

        self.interval = interval

        self.temp_property = HomieNodeProperty(
            id="temperature",
            name="Temperature",
            datatype="float",
            format="-40:80",
            unit="°F",
        )
        self.add_property(self.temp_property)

        loop = get_event_loop()
        loop.create_task(self.update_data())
        # Mensagem a enviar pelo sx127x.py:
        lora.println(payload)

        sleep(5)


#####----- LoRa -----#####
controller = ESP32Controller()
lora = controller.add_transceiver(
    SX127x(name='LoRa'),
    pin_id_ss=ESP32Controller.PIN_ID_FOR_LORA_SS,
    pin_id_RxDone=ESP32Controller.PIN_ID_FOR_LORA_DIO0)

#####----- DS18X20 -----#####
ds18_pin = Pin(5)
ds18_sensor = DS18X20(OneWire(ds18_pin))

addrs = ds18_sensor.scan()
addr = addrs.pop()

ds_read = ds18_sensor.convert_temp()
sleep_ms(750)
ds18_temp = ds18_sensor.read_temp(addr)
# ds18_temp_print = str('%3.2f C  DS18X20' %temp_ds)

#####----- ph -----#####
pH = ADC(Pin(25))
pH.atten(ADC.ATTN_11DB)  # Reading range: 3.3V

# Creat empty list for value storage
buf_ph = []