diff --git a/measurement.py b/measurement.py index d17cd7d..2a45ab5 100644 --- a/measurement.py +++ b/measurement.py @@ -43,7 +43,7 @@ def measure_all_sensors(debug, filtered_temperature, ds18b20Sensors, bme680Senso ds18b20_temperature = ds18b20_temperature-float(sensor["offset"]) ds18b20_temperature = float("{0:.2f}".format(ds18b20_temperature)) # round to two decimals ts_fields.update({sensor["ts_field"]: ds18b20_temperature}) - elif 'ts_field' and 'device_id' in sensor: + elif 'ts_field' in sensor: # Case for filtered_temperature was not filled, use direct measured temperture in this case ds18b20_temperature = measure_temperature(sensor) if sensor["ts_field"] and ds18b20_temperature is not None: diff --git a/read_bme680.py b/read_bme680.py index 44abe45..5a527ba 100644 --- a/read_bme680.py +++ b/read_bme680.py @@ -34,7 +34,7 @@ def initBME680(ts_sensor): print('BME680: The Temperature Offset is ' + str(offset) + ' °C') except: offset = 0 - print('BME680: The Temperature Offset is default: ' + str(offset) + '°C') + #print('BME680: The Temperature Offset is default: ' + str(offset) + '°C') # These oversampling settings can be tweaked to change the balance between accuracy and noise in the data. sensor.set_humidity_oversample(bme680.OS_2X) @@ -57,10 +57,9 @@ def initBME680(ts_sensor): def initBME680FromMain(ts_sensor): if isSMBusConnected(): - print("A Sensor (eg. BME680/WittyPi) is connected to SMBus.") return initBME680(ts_sensor) else: - print("SMBus is not connected.") + print("No I2C sensor connected to SMBus. Please check sensor or remove BME680 from settings.") return 0 def burn_in_bme680(sensor, burn_in_time): diff --git a/read_ds18b20.py b/read_ds18b20.py index 7a6617d..62bf7d5 100644 --- a/read_ds18b20.py +++ b/read_ds18b20.py @@ -15,24 +15,30 @@ def measure_temperature(sensor): try: + if 'device_id' not in sensor: + sensor["device_id"] = "undefined" + if 'pin' in sensor and isinstance(sensor["pin"], (int)) and sensor["pin"] > 0: + print("GPIO" + str(sensor["pin"]) + " is defined as 3.3V power source for Ds18b20 '" + sensor["device_id"] + "'") setup_gpio(sensor["pin"]) + if sensor["device_id"] != "undefined": + if (os.path.isdir("/sys/bus/w1/devices/" + sensor["device_id"]) == False): - error_log("Info: Resetting 3.3V GPIO " + str(sensor["pin"]) + " because " + sensor["device_id"] + " was missing.") + error_log("Info: Resetting 3.3V GPIO" + str(sensor["pin"]) + " because Ds18b20 with device-id '" + sensor["device_id"] + "' was missing.") reset_ds18b20_3V(sensor["pin"]) - # read 1-wire slave file - with open('/sys/bus/w1/devices/' + sensor["device_id"] + '/w1_slave', 'r') as file: - file_content = file.read() - file.close() + # read 1-wire slave file + with open('/sys/bus/w1/devices/' + sensor["device_id"] + '/w1_slave', 'r') as file: + file_content = file.read() + file.close() - # read temperature and convert temperature - string_value = file_content.split("\n")[1].split(" ")[9] - temperature = float(string_value[2:]) / 1000 - temperature = float('%6.2f' % temperature) + # read temperature and convert temperature + string_value = file_content.split("\n")[1].split(" ")[9] + temperature = float(string_value[2:]) / 1000 + temperature = float('%6.2f' % temperature) - return temperature + return temperature except FileNotFoundError: error_log("Warning: Cannot find Device-ID from Ds18b20 Sensor " + sensor["device_id"])