Skip to content

Commit

Permalink
fixed float exception
Browse files Browse the repository at this point in the history
  • Loading branch information
JavanXD committed Apr 20, 2020
1 parent 28302e4 commit 28251b8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ def measure_all_sensors(debug, filtered_temperature, ds18b20Sensors, bme680Senso
# if we have at leat one filtered value we can upload
ds18b20_temperature = filtered_temperature[sensorIndex].pop()
if sensor["ts_field"] and ds18b20_temperature is not None:
if 'offset' in sensor:
if 'offset' in sensor and sensor["offset"] is not None:
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' 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:
if 'offset' in sensor:
if 'offset' in sensor and sensor["offset"] is not None:
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})
except Exception as e:
error_log(e, "Unhandled Exception in measure_all_sensors / ds18b20Sensors")
Expand Down
2 changes: 1 addition & 1 deletion read_bme280.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def measure_bme280(ts_sensor):
# ThingSpeak fields
# Create returned dict if ts-field is defined
if 'ts_field_temperature' in ts_sensor and isinstance(temperature, (int, float)):
if 'offset' in ts_sensor and isinstance(ts_sensor["offset"], (int, float)):
if 'offset' in ts_sensor and ts_sensor["offset"] is not None:
temperature = temperature-ts_sensor["offset"]
fields[ts_sensor["ts_field_temperature"]] = round(temperature, 2)
if 'ts_field_humidity' in ts_sensor and isinstance(humidity, (int, float)):
Expand Down
4 changes: 2 additions & 2 deletions read_dht.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def measure_dht(ts_sensor):

# Create returned dict if ts-field is defined
if 'ts_field_temperature' in ts_sensor and temperature is not None:
if 'offset' in ts_sensor and ts_sensor["offset"] is not None:
temperature = temperature-float(ts_sensor["offset"])
# limit to 2 digits
temperature = float("{0:.2f}".format(temperature))
if 'offset' in ts_sensor:
temperature = temperature-float(ts_sensor["offset"])
fields[ts_sensor["ts_field_temperature"]] = temperature
if 'ts_field_humidity' in ts_sensor and humidity is not None:
# limit to 2 digits
Expand Down

0 comments on commit 28251b8

Please sign in to comment.