Last temperature shown when sensor gets disconnected #412

Open
opened 2021-03-16 17:14:07 +00:00 by dwery · 1 comment
dwery commented 2021-03-16 17:14:07 +00:00 (Migrated from github.com)

I accidentally disconnected my I2C BME280 sensor, and the UI kept showing the last temperature instead of something like -1/error.

I accidentally disconnected my I2C BME280 sensor, and the UI kept showing the last temperature instead of something like -1/error.
wickedbeernut commented 2021-03-22 22:24:19 +00:00 (Migrated from github.com)

I've encountered the same issue.

check_enclosure_temp invokes get_sensor_data which in turn invokes read_bme280_temp which in turn invokes the BME280.py Python script. With the BME280 temperature / humidity sensor disconnected, the Python script returns -1, -1 corresponding to the temperature and humidity.

Since the temperature or humidity is -1, get_sensor_data returns None, None. Consequently, check_enclosure_temp ignores the sensor data and the temperature and humidity are never updated.

I'd like to try to differentiate the case in which the BME280 sensor is disconnected (-1, -1) and the case in which the BME280 sensor returns bogus values (negative values other than -1). I have five BME280 sensors and several other I2C devices on the same bus. Periodically, a BME280 sensor (while connected) will return negative values. With the BME280 sensor disconnected, I'd like the temperature and humidity updated to read "-1" or "err" as @dwery suggested. However, with negative values other than -1, I'd prefer to ignore the temperature and humidity reading as is currently the case. I have several 'heater' and 'cooler' controllers based on BME280 sensors. If infrequent invalid temperature readings aren't ignored, the controller is effectively disabled until the next reading (10 seconds later).

    def check_enclosure_temp(self):
                temp, hum = self.get_sensor_data(sensor)
                if temp is not None and hum is not None:
                    sensor["temp_sensor_temp"] = temp
                    sensor["temp_sensor_humidity"] = hum

    def get_sensor_data(self, sensor):
                elif sensor['temp_sensor_type'] == "bme280":
                    temp, hum = self.read_bme280_temp(sensor['temp_sensor_address'])
            if temp != -1 and hum != -1:
                return temp, hum
            return None, None

    def read_bme280_temp(self, address):
            script = os.path.dirname(os.path.realpath(__file__)) + "/BME280.py "
            temp_to_float = self.to_float(temp.strip())
            return (self.to_float(temp.strip()), self.to_float(hum.strip()))
I've encountered the same issue. check_enclosure_temp invokes get_sensor_data which in turn invokes read_bme280_temp which in turn invokes the BME280.py Python script. With the BME280 temperature / humidity sensor disconnected, the Python script returns -1, -1 corresponding to the temperature and humidity. Since the temperature or humidity is -1, get_sensor_data returns None, None. Consequently, check_enclosure_temp ignores the sensor data and the temperature and humidity are never updated. I'd like to try to differentiate the case in which the BME280 sensor is disconnected (-1, -1) and the case in which the BME280 sensor returns bogus values (negative values other than -1). I have five BME280 sensors and several other I2C devices on the same bus. Periodically, a BME280 sensor (while connected) will return negative values. With the BME280 sensor disconnected, I'd like the temperature and humidity updated to read "-1" or "err" as @dwery suggested. However, with negative values other than -1, I'd prefer to ignore the temperature and humidity reading as is currently the case. I have several 'heater' and 'cooler' controllers based on BME280 sensors. If infrequent invalid temperature readings aren't ignored, the controller is effectively disabled until the next reading (10 seconds later). ``` def check_enclosure_temp(self): temp, hum = self.get_sensor_data(sensor) if temp is not None and hum is not None: sensor["temp_sensor_temp"] = temp sensor["temp_sensor_humidity"] = hum def get_sensor_data(self, sensor): elif sensor['temp_sensor_type'] == "bme280": temp, hum = self.read_bme280_temp(sensor['temp_sensor_address']) if temp != -1 and hum != -1: return temp, hum return None, None def read_bme280_temp(self, address): script = os.path.dirname(os.path.realpath(__file__)) + "/BME280.py " temp_to_float = self.to_float(temp.strip()) return (self.to_float(temp.strip()), self.to_float(hum.strip())) ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Gandalf/OctoPrint-Enclosure#412