From f84374ca565de1e96e4aade65354e77009374484 Mon Sep 17 00:00:00 2001 From: Keir Rice Date: Sat, 24 Sep 2022 21:14:15 +1200 Subject: [PATCH 01/12] Added support for SHTC3 module --- octoprint_enclosure/SHTC3.py | 185 ++++++++++++++++++ octoprint_enclosure/__init__.py | 21 ++ .../templates/enclosure_settings.jinja2 | 5 +- 3 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 octoprint_enclosure/SHTC3.py diff --git a/octoprint_enclosure/SHTC3.py b/octoprint_enclosure/SHTC3.py new file mode 100644 index 0000000..6eb2c98 --- /dev/null +++ b/octoprint_enclosure/SHTC3.py @@ -0,0 +1,185 @@ +import sys +import time + +from smbus2 import SMBus, i2c_msg + +try: + import struct +except ImportError: + import ustruct as struct + +from crc import CrcCalculator, Configuration +width = 8 +poly = 0x31 +init_value = 0xFF +final_xor_value = 0x00 +reverse_input = False +reverse_output = False +configuration = Configuration(width, poly, init_value, final_xor_value, reverse_input, reverse_output) + +use_table = True +crc_calculator = CrcCalculator(configuration, use_table) + + +class SHTC3Exception(Exception): + """ Base class for exception """ + + +class SHTC3DeviceNotFound(SHTC3Exception, ValueError): + """ Device not found """ + + +class SHTC3ReadError(SHTC3Exception, RuntimeError): + """ Read error or CRC mismatch """ + + +CMD_SLEEP = 0xB098 +CMD_WAKE = 0x3517 # 240µs +CMD_RESET = 0x805D # 240µs + +CMD_READ_ID = 0xEFC8 + +# Normal sample time 12ms +# Low sample time 0.8ms +CMD_NORMAL_T = 0x7866 +CMD_NORMAL_RH = 0x58E0 +CMD_LOW_T = 0x609C +CMD_LOW_RH = 0x401A + +CMD_NORMAL_STRETCH_T = 0x7CA2 +CMD_NORMAL_STRETCH_RH = 0x5C24 +CMD_LOW_STRETCH_T = 0x6458 +CMD_LOW_STRETCH_RH = 0x44DE + +SHTC3_I2CADDR_DEFAULT = 0x70 + + +def send_command(bus, address, cmd): + """Write the command bytes to the bus.""" + byte_array = cmd.to_bytes(2, 'big') + for b in byte_array: + bus.write_byte_data(address, 0, b) + time.sleep(0.001) + + +def write_then_read(bus, address, cmd, read_length): + """In a single transaction write a cmd, then read the result.""" + cmd_bytes = cmd.to_bytes(2, 'big') + write = i2c_msg.write(address, cmd_bytes) + read = i2c_msg.read(address, read_length) + + bus.i2c_rdwr(write, read) + + return bytearray(read) + + +def process_crc(bytes_array): + """Assume the last byte in the array is the CRC and check it matches the rest of the message. + Return just the message bytes.""" + crc_byte = bytes_array[-1] + bytes_array = bytes_array[:-1] + + if not crc_calculator.verify_checksum(bytes_array, crc_byte): + raise RuntimeError('Checksum failed') + return bytes_array + + +def to_relative_humidity(raw_data): + """Convert the linearized 16 bit values into Relative humidity (result in %RH) + + Source: https://sensirion.com/media/documents/643F9C8E/6164081E/Sensirion_Humidity_Sensors_SHTC3_Datasheet.pdf + """ + return 100.0 * (raw_data / 2 ** 16) + + +def to_temperature(raw_data): + """Convert the linearized 16 bit values into Temperature (result in °C) + + Source: https://sensirion.com/media/documents/643F9C8E/6164081E/Sensirion_Humidity_Sensors_SHTC3_Datasheet.pdf + """ + return -45 + 175 * (raw_data / 2 ** 16) + + +def sample_temperature(bus, address): + + send_command(bus, CMD_RESET) + time.sleep(0.001) + send_command(bus, CMD_WAKE) + time.sleep(0.001) + + try: + result = write_then_read(bus, address, CMD_NORMAL_STRETCH_T, 3) + raw_temp, crc = struct.unpack(">HI", result) + + if not crc_calculator.verify_checksum(result[:-1], crc): + raise SHTC3ReadError('CRC Mismatch') + + return to_temperature(raw_temp) + + finally: + send_command(bus, CMD_SLEEP) + + +def sample_humidity(bus, address): + send_command(bus, address, CMD_RESET) + time.sleep(0.001) + send_command(bus, address, CMD_WAKE) + time.sleep(0.001) + + try: + result = write_then_read(bus, address, CMD_NORMAL_STRETCH_RH, 3) + raw_rh, crc = struct.unpack(">HI", result) + + if not crc_calculator.verify_checksum(result[:-1], crc): + raise SHTC3ReadError('CRC Mismatch') + + return to_relative_humidity(raw_rh) + + finally: + send_command(bus, address, CMD_SLEEP) + + +def sample_both(bus, address): + """Sample of temperature and humidity.""" + + send_command(bus, address, CMD_RESET) + send_command(bus, address, CMD_WAKE) + + try: + result = write_then_read(bus, address, CMD_NORMAL_STRETCH_T, 6) + + raw_temp, crc_temp, raw_rh, crc_rh = struct.unpack(">HI>HI", result) + + if not crc_calculator.verify_checksum(result[0:2], crc_temp): + raise SHTC3ReadError('CRC Mismatch') + + if not crc_calculator.verify_checksum(result[3:5], raw_rh): + raise SHTC3ReadError('CRC Mismatch') + + temperature = to_temperature(raw_temp) + humidity = to_relative_humidity(raw_rh) + + return temperature, humidity + + finally: + # Sleep + send_command(bus, address, CMD_SLEEP) + + +def main(): + # get i2c bus and bus address if provided or use defaults + address = SHTC3_I2CADDR_DEFAULT + bus = SMBus(1) + if len(sys.argv) > 1: + bus = SMBus(int(sys.argv[1])) + address = int(sys.argv[2], 16) + + try: + temperature, humidity = sample_both(bus, address) + print('{0:0.1f} | {1:0.1f}'.format(temperature, humidity)) + except Exception: + print('-1 | -1') + + +if __name__ == "__main__": + main() diff --git a/octoprint_enclosure/__init__.py b/octoprint_enclosure/__init__.py index 72d8376..1799ec4 100644 --- a/octoprint_enclosure/__init__.py +++ b/octoprint_enclosure/__init__.py @@ -1045,6 +1045,9 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP elif sensor['temp_sensor_type'] == "hum_raw_i2c": hum, temp = self.read_raw_i2c_temp(sensor) airquality = 0 + elif sensor['temp_sensor_type'] == "shtc3": + temp, hum = self.read_shtc3_temp(sensor['temp_sensor_address'], sensor['temp_sensor_i2cbus']) + airquality = 0 else: self._logger.info("temp_sensor_type no match") temp = None @@ -1137,6 +1140,24 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP self.log_error(ex) return 0 + def read_shtc3_temp(self, address, i2cbus): + try: + script = os.path.dirname(os.path.realpath(__file__)) + "/SHTC3.py" + args = ["python", script, str(i2cbus), str(address)] + if self._settings.get(["debug_temperature_log"]) is True: + self._logger.debug("Temperature SHTC3 cmd: %s", " ".join(args)) + proc = Popen(args, stdout=PIPE) + stdout, _ = proc.communicate() + if self._settings.get(["debug_temperature_log"]) is True: + self._logger.debug("SHTC3 result: %s", stdout) + temp, hum = stdout.decode("utf-8").split("|") + return self.to_float(temp.strip()), self.to_float(hum.strip()) + + except Exception as ex: + self._logger.info("Failed to execute python scripts, try disabling use SUDO on advanced section.") + self.log_error(ex) + return 0, 0 + def read_dht_temp(self, sensor, pin): try: script = os.path.dirname(os.path.realpath(__file__)) + "/getDHTTemp.py " diff --git a/octoprint_enclosure/templates/enclosure_settings.jinja2 b/octoprint_enclosure/templates/enclosure_settings.jinja2 index 473ebb0..afcabc5 100644 --- a/octoprint_enclosure/templates/enclosure_settings.jinja2 +++ b/octoprint_enclosure/templates/enclosure_settings.jinja2 @@ -617,6 +617,7 @@ + @@ -682,7 +683,7 @@ - +
@@ -732,7 +733,7 @@
- +
-- 2.39.5 From 5af13e87143b5b3da4d742549953e536e2620e4e Mon Sep 17 00:00:00 2001 From: Keir Rice Date: Sat, 24 Sep 2022 22:25:41 +1200 Subject: [PATCH 02/12] Fixed mistake in unpacking the data. Also fixed an issue with the CRC calculation. The CRC calculations need the raw bytes, not unpacked values. --- octoprint_enclosure/SHTC3.py | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/octoprint_enclosure/SHTC3.py b/octoprint_enclosure/SHTC3.py index 6eb2c98..78c8def 100644 --- a/octoprint_enclosure/SHTC3.py +++ b/octoprint_enclosure/SHTC3.py @@ -70,18 +70,7 @@ def write_then_read(bus, address, cmd, read_length): bus.i2c_rdwr(write, read) - return bytearray(read) - - -def process_crc(bytes_array): - """Assume the last byte in the array is the CRC and check it matches the rest of the message. - Return just the message bytes.""" - crc_byte = bytes_array[-1] - bytes_array = bytes_array[:-1] - - if not crc_calculator.verify_checksum(bytes_array, crc_byte): - raise RuntimeError('Checksum failed') - return bytes_array + return bytes(read) def to_relative_humidity(raw_data): @@ -102,22 +91,22 @@ def to_temperature(raw_data): def sample_temperature(bus, address): - send_command(bus, CMD_RESET) + send_command(bus, address, CMD_RESET) time.sleep(0.001) - send_command(bus, CMD_WAKE) + send_command(bus, address, CMD_WAKE) time.sleep(0.001) try: result = write_then_read(bus, address, CMD_NORMAL_STRETCH_T, 3) - raw_temp, crc = struct.unpack(">HI", result) - if not crc_calculator.verify_checksum(result[:-1], crc): + if not crc_calculator.verify_checksum(result[0:2], result[2]): raise SHTC3ReadError('CRC Mismatch') + raw_temp, crc = struct.unpack(">HB", result) return to_temperature(raw_temp) finally: - send_command(bus, CMD_SLEEP) + send_command(bus, address, CMD_SLEEP) def sample_humidity(bus, address): @@ -128,11 +117,11 @@ def sample_humidity(bus, address): try: result = write_then_read(bus, address, CMD_NORMAL_STRETCH_RH, 3) - raw_rh, crc = struct.unpack(">HI", result) - if not crc_calculator.verify_checksum(result[:-1], crc): + if not crc_calculator.verify_checksum(result[0:2], result[2]): raise SHTC3ReadError('CRC Mismatch') + raw_rh, crc = struct.unpack(">HB", result) return to_relative_humidity(raw_rh) finally: @@ -148,14 +137,13 @@ def sample_both(bus, address): try: result = write_then_read(bus, address, CMD_NORMAL_STRETCH_T, 6) - raw_temp, crc_temp, raw_rh, crc_rh = struct.unpack(">HI>HI", result) - - if not crc_calculator.verify_checksum(result[0:2], crc_temp): + if not crc_calculator.verify_checksum(result[0:2], result[2]): raise SHTC3ReadError('CRC Mismatch') - if not crc_calculator.verify_checksum(result[3:5], raw_rh): + if not crc_calculator.verify_checksum(result[3:5], result[5]): raise SHTC3ReadError('CRC Mismatch') + raw_temp, crc_temp, raw_rh, crc_rh = struct.unpack(">HBHB", result) temperature = to_temperature(raw_temp) humidity = to_relative_humidity(raw_rh) @@ -177,6 +165,7 @@ def main(): try: temperature, humidity = sample_both(bus, address) print('{0:0.1f} | {1:0.1f}'.format(temperature, humidity)) + except Exception: print('-1 | -1') -- 2.39.5 From 0b822349ec4b661afdb3c0cc47d3b421213d3083 Mon Sep 17 00:00:00 2001 From: Keir Rice Date: Sat, 24 Sep 2022 22:45:14 +1200 Subject: [PATCH 03/12] Missing dependency --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 61d2cc5..3823d12 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ plugin_url = "https://github.com/vitormhenrique/OctoPrint-Enclosure" plugin_license = "AGPLv3" # Any additional requirements besides OctoPrint should be listed here -plugin_requires = ["RPi.GPIO>=0.6.5", "requests>=2.7", "smbus2>=0.3.0", "gpiozero==1.6.2", "RPi.bme280", "bme680"] +plugin_requires = ["RPi.GPIO>=0.6.5", "requests>=2.7", "smbus2>=0.3.0", "gpiozero==1.6.2", "RPi.bme280", "bme680", "crc"] additional_setup_parameters = {} -- 2.39.5 From bb6c908eec321ac8c040d801ca5e8838e0adb6f6 Mon Sep 17 00:00:00 2001 From: Keir Rice Date: Sat, 24 Sep 2022 22:59:42 +1200 Subject: [PATCH 04/12] Having trouble getting the script to run in the enclosure framework. Trying a differant aproach to popen. --- octoprint_enclosure/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/octoprint_enclosure/__init__.py b/octoprint_enclosure/__init__.py index 1799ec4..bf308f5 100644 --- a/octoprint_enclosure/__init__.py +++ b/octoprint_enclosure/__init__.py @@ -1143,11 +1143,14 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP def read_shtc3_temp(self, address, i2cbus): try: script = os.path.dirname(os.path.realpath(__file__)) + "/SHTC3.py" - args = ["python", script, str(i2cbus), str(address)] + if self._settings.get(["use_sudo"]): + sudo_str = "sudo " + else: + sudo_str = "" + cmd = sudo_str + "python3 " + script + " " + str(i2cbus) + " " + str(address) if self._settings.get(["debug_temperature_log"]) is True: - self._logger.debug("Temperature SHTC3 cmd: %s", " ".join(args)) - proc = Popen(args, stdout=PIPE) - stdout, _ = proc.communicate() + self._logger.debug("Temperature SHTC3 cmd: %s", " ".join(cmd)) + stdout = (Popen(cmd, shell=True, stdout=PIPE).stdout).read() if self._settings.get(["debug_temperature_log"]) is True: self._logger.debug("SHTC3 result: %s", stdout) temp, hum = stdout.decode("utf-8").split("|") -- 2.39.5 From 7c3c93f59215b4ea9959505729f2ab1a7394a67b Mon Sep 17 00:00:00 2001 From: Keir Rice Date: Sat, 24 Sep 2022 22:59:42 +1200 Subject: [PATCH 05/12] Having trouble getting the script to run in the enclosure framework. Trying a differant aproach to popen. --- octoprint_enclosure/__init__.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/octoprint_enclosure/__init__.py b/octoprint_enclosure/__init__.py index 1799ec4..b4f02ec 100644 --- a/octoprint_enclosure/__init__.py +++ b/octoprint_enclosure/__init__.py @@ -1143,14 +1143,23 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP def read_shtc3_temp(self, address, i2cbus): try: script = os.path.dirname(os.path.realpath(__file__)) + "/SHTC3.py" - args = ["python", script, str(i2cbus), str(address)] + cmd = [sys.executable, script, str(i2cbus), str(address)] + if self._settings.get(["use_sudo"]): + cmd.insert(0, "sudo") + if self._settings.get(["debug_temperature_log"]) is True: - self._logger.debug("Temperature SHTC3 cmd: %s", " ".join(args)) - proc = Popen(args, stdout=PIPE) - stdout, _ = proc.communicate() - if self._settings.get(["debug_temperature_log"]) is True: - self._logger.debug("SHTC3 result: %s", stdout) - temp, hum = stdout.decode("utf-8").split("|") + self._logger.debug("Temperature SHTC3 cmd: %s", " ".join(cmd)) + + stdout = Popen(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True) + output, errors = stdout.communicate() + + if self._settings.get(["debug_temperature_log"]) is True: + if len(errors) > 0: + self._logger.error("SHTC3 error: %s", errors) + else: + self._logger.debug("SHTC3 result: %s", output) + + temp, hum = output.split("|") return self.to_float(temp.strip()), self.to_float(hum.strip()) except Exception as ex: -- 2.39.5 From 3491f07e3839504c07bcb45918456d5a3aa68a26 Mon Sep 17 00:00:00 2001 From: Keir Rice Date: Sun, 25 Sep 2022 19:20:05 +1300 Subject: [PATCH 06/12] Forcing debug messages on. --- octoprint_enclosure/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octoprint_enclosure/__init__.py b/octoprint_enclosure/__init__.py index b4f02ec..48f80be 100644 --- a/octoprint_enclosure/__init__.py +++ b/octoprint_enclosure/__init__.py @@ -1153,11 +1153,11 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP stdout = Popen(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True) output, errors = stdout.communicate() - if self._settings.get(["debug_temperature_log"]) is True: + if True or self._settings.get(["debug_temperature_log"]) is True: if len(errors) > 0: self._logger.error("SHTC3 error: %s", errors) else: - self._logger.debug("SHTC3 result: %s", output) + self._logger.info("SHTC3 result: %s", output) temp, hum = output.split("|") return self.to_float(temp.strip()), self.to_float(hum.strip()) -- 2.39.5 From 95b33db84dec3036b35e58dd880a2e6316a64ddb Mon Sep 17 00:00:00 2001 From: Keir Rice Date: Sun, 25 Sep 2022 19:24:28 +1300 Subject: [PATCH 07/12] Ignoring the option to sudo. --- octoprint_enclosure/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octoprint_enclosure/__init__.py b/octoprint_enclosure/__init__.py index 48f80be..ea7d033 100644 --- a/octoprint_enclosure/__init__.py +++ b/octoprint_enclosure/__init__.py @@ -1144,8 +1144,8 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP try: script = os.path.dirname(os.path.realpath(__file__)) + "/SHTC3.py" cmd = [sys.executable, script, str(i2cbus), str(address)] - if self._settings.get(["use_sudo"]): - cmd.insert(0, "sudo") + # if self._settings.get(["use_sudo"]): + # cmd.insert(0, "sudo") if self._settings.get(["debug_temperature_log"]) is True: self._logger.debug("Temperature SHTC3 cmd: %s", " ".join(cmd)) -- 2.39.5 From 7d5a7d687da2642301a0843497ae2b96472442c5 Mon Sep 17 00:00:00 2001 From: Keir Rice Date: Sun, 25 Sep 2022 19:51:35 +1300 Subject: [PATCH 08/12] Narrowing in on an issue with settings saving --- octoprint_enclosure/templates/enclosure_settings.jinja2 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/octoprint_enclosure/templates/enclosure_settings.jinja2 b/octoprint_enclosure/templates/enclosure_settings.jinja2 index afcabc5..473ebb0 100644 --- a/octoprint_enclosure/templates/enclosure_settings.jinja2 +++ b/octoprint_enclosure/templates/enclosure_settings.jinja2 @@ -617,7 +617,6 @@ - @@ -683,7 +682,7 @@
- +
@@ -733,7 +732,7 @@
- +
-- 2.39.5 From 2ef21e9da22ebceb8279e1d6f6b6faad7d26c8e8 Mon Sep 17 00:00:00 2001 From: Keir Rice Date: Sun, 25 Sep 2022 20:17:54 +1300 Subject: [PATCH 09/12] Trying to add the settings again. --- octoprint_enclosure/static/js/enclosure.js | 2 +- .../templates/enclosure_settings.jinja2 | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/octoprint_enclosure/static/js/enclosure.js b/octoprint_enclosure/static/js/enclosure.js index 5e0a935..d1cca41 100644 --- a/octoprint_enclosure/static/js/enclosure.js +++ b/octoprint_enclosure/static/js/enclosure.js @@ -56,7 +56,7 @@ $(function () { self.notifications = ko.observableArray([]); self.humidityCapableSensor = function(sensor){ - if (['11', '20', '22', '2302', 'bme280', 'bme680', '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', 'shtc3'].indexOf(sensor) >= 0){ return true; } return false; diff --git a/octoprint_enclosure/templates/enclosure_settings.jinja2 b/octoprint_enclosure/templates/enclosure_settings.jinja2 index 473ebb0..810ed76 100644 --- a/octoprint_enclosure/templates/enclosure_settings.jinja2 +++ b/octoprint_enclosure/templates/enclosure_settings.jinja2 @@ -604,7 +604,7 @@ @@ -663,7 +664,7 @@ GPIO pin for temperature sensor, recommended to use 4 as DS18B20 has default support to pin #4 (BCM)
-
+
GPIO pin for temperature sensor, recommended to use 4 as DS18B20 only works on pin 4
-- 2.39.5 From 57a81b307a257742c135543ccd29b5a78687106d Mon Sep 17 00:00:00 2001 From: Keir Rice Date: Sun, 25 Sep 2022 20:42:10 +1300 Subject: [PATCH 10/12] Found a missing bracket --- octoprint_enclosure/templates/enclosure_settings.jinja2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/octoprint_enclosure/templates/enclosure_settings.jinja2 b/octoprint_enclosure/templates/enclosure_settings.jinja2 index 810ed76..b61ca61 100644 --- a/octoprint_enclosure/templates/enclosure_settings.jinja2 +++ b/octoprint_enclosure/templates/enclosure_settings.jinja2 @@ -683,7 +683,7 @@
- +
@@ -736,7 +736,7 @@
-
+
GPIO pin for temperature sensor, recommended to use 4 as DS18B20 only works on pin 4
-- 2.39.5 From d6be2b13d7b6f19088aff6361076f8d7c0e68d6c Mon Sep 17 00:00:00 2001 From: Keir Rice Date: Sun, 25 Sep 2022 20:53:05 +1300 Subject: [PATCH 11/12] And another bad bracket. --- octoprint_enclosure/templates/enclosure_settings.jinja2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/octoprint_enclosure/templates/enclosure_settings.jinja2 b/octoprint_enclosure/templates/enclosure_settings.jinja2 index b61ca61..6b217f0 100644 --- a/octoprint_enclosure/templates/enclosure_settings.jinja2 +++ b/octoprint_enclosure/templates/enclosure_settings.jinja2 @@ -733,7 +733,7 @@
- +
-- 2.39.5 From 7a445e04136ef66390ad7d176716aeb929311495 Mon Sep 17 00:00:00 2001 From: Keir Rice Date: Sun, 25 Sep 2022 21:18:02 +1300 Subject: [PATCH 12/12] Clean up the logging to respect settings. Re-enable the use of SUDO when set. --- octoprint_enclosure/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/octoprint_enclosure/__init__.py b/octoprint_enclosure/__init__.py index ea7d033..07e5773 100644 --- a/octoprint_enclosure/__init__.py +++ b/octoprint_enclosure/__init__.py @@ -1144,8 +1144,8 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP try: script = os.path.dirname(os.path.realpath(__file__)) + "/SHTC3.py" cmd = [sys.executable, script, str(i2cbus), str(address)] - # if self._settings.get(["use_sudo"]): - # cmd.insert(0, "sudo") + if self._settings.get(["use_sudo"]): + cmd.insert(0, "sudo") if self._settings.get(["debug_temperature_log"]) is True: self._logger.debug("Temperature SHTC3 cmd: %s", " ".join(cmd)) @@ -1153,7 +1153,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP stdout = Popen(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True) output, errors = stdout.communicate() - if True or self._settings.get(["debug_temperature_log"]) is True: + if self._settings.get(["debug_temperature_log"]) is True: if len(errors) > 0: self._logger.error("SHTC3 error: %s", errors) else: -- 2.39.5