From 34f35cf13afd0410f99ce7447a072546e8a7cc5b Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Sun, 10 Jan 2021 03:22:37 +0100 Subject: [PATCH] Discard first DS18B12 measurement on ESP Looks a bit like it's in fahrenheit, but it is definitely messing up my graphs! --- mqtt_sensord/sensorlib/esp_sensors.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mqtt_sensord/sensorlib/esp_sensors.py b/mqtt_sensord/sensorlib/esp_sensors.py index 8f15a61..1ddf109 100644 --- a/mqtt_sensord/sensorlib/esp_sensors.py +++ b/mqtt_sensord/sensorlib/esp_sensors.py @@ -18,11 +18,18 @@ class DS18B20(Sensor): self.o = onewire.OneWire(machine.Pin(self.pin)) self.ds = ds18x20.DS18X20(self.o) self.sID = self.ds.scan()[0] + self._first_measurement = True def get_data(self): self.ds.convert_temp() time.sleep(0.1) - return {"temp": self.ds.read_temp(self.sID)} + val = self.ds.read_temp(self.sID) + if self._first_measurement: + if val > 70.0: + val = None + else: + self._first_measurement = False + return {"temp": val} @sensor