Merge branch 'master' into master

This commit is contained in:
deafloo
2022-02-27 14:31:21 +01:00
committed by GitHub
5 changed files with 69 additions and 54 deletions

View File

@@ -1,6 +1,9 @@
Find the plugin useful? Buy me a coffee
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/VitorHenrique/2)
# THIS PLUGIN IS DEPRACATED!
I'm moving away from it, and when ready the replacement plugin would be here: https://github.com/vitormhenrique/OctoPrint-Enclosure-V2
# Before opening an issue...
Check the [troubleshooting guide](https://github.com/vitormhenrique/OctoPrint-Enclosure/wiki/Troubleshooting-Guide). Issues with no log, no print screen *will be closed* until the necessary documentation is available.

View File

@@ -2,33 +2,11 @@ import bme680
import time
try:
sensor = bme680.BME680(bme680.I2C_ADDR_PRIMARY)
except IOError:
sensor = bme680.BME680(bme680.I2C_ADDR_SECONDARY)
hum_weighting = float(0.25) # so hum effect is 25% of the total air quality score
gas_weighting = float(0.75) # so gas effect is 75% of the total air quality score
sensor.set_humidity_oversample(bme680.OS_2X)
sensor.set_pressure_oversample(bme680.OS_2X)
sensor.set_temperature_oversample(bme680.OS_2X)
sensor.set_filter(bme680.FILTER_SIZE_3)
sensor.set_gas_heater_temperature(320)
sensor.set_gas_heater_duration(150)
sensor.select_gas_heater_profile(0)
sensor.set_gas_status(bme680.ENABLE_GAS_MEAS)
gas_reference = float(250000)
hum_reference = float(40)
getgasreference_count = int(0)
def GetGasReference(gas_reference):
def GetGasReference():
# Now run the sensor for a burn-in period, then use combination of relative humidity and gas resistance to estimate indoor air quality as a percentage.
# print("Getting a new gas reference value")
readings = int(10)
gas_reference = 0
while True:
sensor.get_sensor_data()
if sensor.data.heat_stable:
@@ -36,7 +14,8 @@ def GetGasReference(gas_reference):
sensor.get_sensor_data()
gas_reference = gas_reference + sensor.data.gas_resistance
gas_reference = gas_reference / readings
return
return gas_reference
def CalculateIAQ(score):
IAQ_text = "Air quality is "
@@ -55,32 +34,65 @@ def CalculateIAQ(score):
IAQ_text = IAQ_text + "Good"
return IAQ_text
#Calculate humidity contribution to IAQ index
current_humidity = float(sensor.data.humidity)
if (current_humidity >= 38 and current_humidity <= 42):
hum_score = float(0.25*100) # Humidity +/-5% around optimum
else:
#sub-optimal
if (current_humidity < 38):
hum_score = float(0.25/hum_reference*current_humidity*100)
if __name__ == "__main__":
try:
sensor = bme680.BME680(bme680.I2C_ADDR_PRIMARY)
except RuntimeError:
try:
sensor = bme680.BME680(bme680.I2C_ADDR_SECONDARY)
except Exception as ex:
print(ex)
quit(-1)
hum_weighting = float(0.25) # so hum effect is 25% of the total air quality score
gas_weighting = float(0.75) # so gas effect is 75% of the total air quality score
sensor.set_humidity_oversample(bme680.OS_2X)
sensor.set_pressure_oversample(bme680.OS_2X)
sensor.set_temperature_oversample(bme680.OS_2X)
sensor.set_filter(bme680.FILTER_SIZE_3)
sensor.get_sensor_data()
temperature = sensor.data.temperature
humidity = sensor.data.humidity
sensor.set_gas_heater_temperature(320)
sensor.set_gas_heater_duration(150)
sensor.select_gas_heater_profile(0)
sensor.set_gas_status(bme680.ENABLE_GAS_MEAS)
gas_reference = float(250000)
hum_reference = float(40)
getgasreference_count = int(0)
# Calculate humidity contribution to IAQ index
current_humidity = float(humidity)
if (current_humidity >= 38 and current_humidity <= 42):
hum_score = float(0.25 * 100) # Humidity +/-5% around optimum
else:
hum_score = ((-0.25/(100-hum_reference)*current_humidity)+0.416666)*100
# sub-optimal
if (current_humidity < 38):
hum_score = float(0.25 / hum_reference * current_humidity * 100)
else:
hum_score = ((-0.25 / (100 - hum_reference) * current_humidity) + 0.416666) * 100
#Calculate gas contribution to IAQ index
gas_lower_limit = float(5000) # Bad air quality limit
gas_upper_limit = float(50000) # Good air quality limit
# Calculate gas contribution to IAQ index
gas_lower_limit = float(5000) # Bad air quality limit
gas_upper_limit = float(50000) # Good air quality limit
if gas_reference > gas_upper_limit:
gas_reference = gas_upper_limit
if gas_reference < gas_lower_limit:
gas_reference = gas_lower_limit
gas_reference = GetGasReference()
gas_score = float((0.75/(gas_upper_limit-gas_lower_limit)*gas_reference -(gas_lower_limit*(0.75/(gas_upper_limit-gas_lower_limit))))*100)
if gas_reference > gas_upper_limit:
gas_reference = gas_upper_limit
if gas_reference < gas_lower_limit:
gas_reference = gas_lower_limit
#Combine results for the final IAQ index value (0-100% where 100% is good quality air)
air_quality_score = float(hum_score + gas_score)
gas_score = float((0.75 / (gas_upper_limit - gas_lower_limit) * gas_reference - (
gas_lower_limit * (0.75 / (gas_upper_limit - gas_lower_limit)))) * 100)
GetGasReference(gas_reference)
print('{0:0.1f}'.format(air_quality_score))
# Combine results for the final IAQ index value (0-100% where 100% is good quality air)
air_quality_score = float(hum_score + gas_score)
print('{:0.1f}|{:0.1f}|{:0.1f}'.format(temperature, humidity, air_quality_score))

View File

@@ -1207,7 +1207,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
def read_bme680_temp(self, address):
try:
script = os.path.dirname(os.path.realpath(__file__)) + "/BME680.py "
script = os.path.dirname(os.path.realpath(__file__)) + "/BME680.py"
cmd = [sys.executable, script, str(address)]
if self._settings.get(["use_sudo"]):
cmd.insert(0, "sudo")
@@ -1228,7 +1228,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
self._logger.info(
"Failed to execute python scripts, try disabling use SUDO on advanced section of the plugin.")
self.log_error(ex)
return (0, 0)
return (0, 0, 0)
def read_am2320_temp(self):
try:

View File

@@ -56,7 +56,7 @@ $(function () {
self.notifications = ko.observableArray([]);
self.humidityCapableSensor = function(sensor){
if (['11', '20', '22', '2302', 'bme280', 'am2320', 'aht10' , 'si7021', 'hum_raw_i2c', 'temp_raw_i2c'].indexOf(sensor) >= 0){
if (['11', '20', '22', '2302', 'bme280', 'bme680', 'am2320', 'aht10' , 'si7021', 'hum_raw_i2c', 'temp_raw_i2c'].indexOf(sensor) >= 0){
return true;
}
return false;

View File

@@ -174,7 +174,7 @@
<label class="control-label">{{ _('Off Time') }}</label>
<div class="controls">
<input type="text" class="input-block-level" data-bind="value: toggle_timer_off">
<span class="help-inline">Time in secconds that the GPIO will remain when OFF</span>
<span class="help-inline">Time in seconds that the GPIO will remain when OFF</span>
</div>
</div>
<!-- /ko -->
@@ -240,7 +240,7 @@
<label class="control-label">{{ _('Shutdown Delay / Hour') }}</label>
<div class="controls">
<input type="text" class="input-block-level" data-bind="value: shutdown_time">
<span class="help-inline">Time delay in secconds to turn on GPIO when print starts OR exact time that the event should happen, note that
<span class="help-inline">Time delay in seconds to turn off GPIO when print starts OR exact time that the event should happen, note that
events will only be scheduled after a print starts, time should be formated as HH:MM on a 24 hours format, don't
forget to check timezone of your raspberry pi.</span>
<span class="label label-important">Attention</span>
@@ -256,7 +256,7 @@
<label class="checkbox">
<input type="checkbox" data-bind="checked: shutdown_on_error"> {{ _('Auto Shutdown on Serial Connection Error') }}
</label>
<span class="help-inline">Choose if output should turn off automatically when an error or disconnect was detected.</span>
<span class="help-inline">Choose if output should turn off automatically when an error or disconnect was detected. Shutdown Delay will be ignored in this case</span>
</div>
</div>
<!-- /ko -->
@@ -279,7 +279,7 @@
<label class="checkbox">
<input type="checkbox" data-bind="checked: gpio_i2c_enabled"> {{ _('GPIO over I2C') }}
</label>
<span class="help-inline">Active low means that the GPIO will turn on when receive a low signal (ground) from Raspberry PI</span>
<span class="help-inline">Allows multiple devices to be connected to the same GPIO pins</span>
</div>
</div>
<!-- /ko -->