Working changes

Confirmed works with 2 Si7021 modules.
This commit is contained in:
ameixler
2020-05-13 20:38:04 -04:00
parent 397ad4dead
commit 3b6233a731
4 changed files with 13 additions and 9 deletions

View File

@@ -3,14 +3,18 @@ import time
import sys
if len(sys.argv) == 2:
if len(sys.argv) == 2 or len(sys.argv) == 3:
address = int(sys.argv[1],16)
if len(sys.argv) == 3:
busNum = int(sys.argv[2],16)
else:
busNum = 1
else:
print('-1 | -1')
sys.exit(1)
# Get I2C bus
bus = smbus.SMBus(1)
bus = smbus.SMBus(busNum)
# SI7021 address, 0x40(64)
# 0xF5(245) Select Relative Humidity NO HOLD master mode

View File

@@ -800,7 +800,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
elif sensor['temp_sensor_type'] == "am2320":
temp, hum = self.read_am2320_temp() # sensor has fixed address
elif sensor['temp_sensor_type'] == "si7021":
temp, hum = self.read_si7021_temp(sensor['temp_sensor_address'])
temp, hum = self.read_si7021_temp(sensor['temp_sensor_address'], sensor['temp_sensor_i2cbus'])
elif sensor['temp_sensor_type'] == "tmp102":
temp = self.read_tmp102_temp(sensor['temp_sensor_address'])
hum = 0
@@ -933,14 +933,14 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
self.log_error(ex)
return (0, 0)
def read_si7021_temp(self, address):
def read_si7021_temp(self, address, i2cbus):
try:
script = os.path.dirname(os.path.realpath(__file__)) + "/SI7021.py "
if self._settings.get(["use_sudo"]):
sudo_str = "sudo "
else:
sudo_str = ""
cmd = sudo_str + "python " + script + str(address)
cmd = sudo_str + "python " + script + str(address) + " " + str(i2cbus)
if self._settings.get(["debug_temperature_log"]) is True:
self._logger.debug("Temperature SI7021 cmd: %s", cmd)
stdout = (Popen(cmd, shell=True, stdout=PIPE).stdout).read()
@@ -1890,4 +1890,4 @@ def __plugin_load__():
__plugin_hooks__ = {
"octoprint.comm.protocol.gcode.queuing" : __plugin_implementation__.hook_gcode_queuing,
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
}
}

View File

@@ -456,7 +456,7 @@ $(function () {
temp_sensor_navbar: ko.observable(true),
filament_sensor_timeout: ko.observable(120),
filament_sensor_enabled: ko.observable(true),
temp_sensor_i2cbus: ko.observable("1")
temp_sensor_i2cbus: ko.observable(1)
});
};
@@ -707,4 +707,4 @@ $(function () {
elements: ["#tab_plugin_enclosure", "#settings_plugin_enclosure", "#navbar_plugin_enclosure_1", "#navbar_plugin_enclosure_2"]
});
});
});

View File

@@ -909,4 +909,4 @@
</div>
<!-- /ko -->
</form>
</div>
</div>