diff --git a/octoprint_enclosure/__init__.py b/octoprint_enclosure/__init__.py
index 63d094c..ae83bb0 100644
--- a/octoprint_enclosure/__init__.py
+++ b/octoprint_enclosure/__init__.py
@@ -555,6 +555,10 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
temp = self.read_tmp102_temp(
sensor['temp_sensor_address'])
hum = 0
+ elif sensor['temp_sensor_type'] == "max31855":
+ temp = self.read_max31855_temp(
+ sensor['temp_sensor_address'])
+ hum = 0
else:
self._logger.info("temp_sensor_type no match")
temp = None
@@ -708,7 +712,24 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
"Failed to excecute python scripts, try disabling use SUDO on advanced section.")
self.log_error(ex)
return 0
-
+
+ def read_max31855_temp(self, address):
+ try:
+ script = os.path.dirname(os.path.realpath(__file__)) + "/max31855.py"
+ args = ["python", script, str(address)]
+ if self._settings.get(["debug"]) is True and self._settings.get(["debug_temperature_log"]) is True:
+ self._logger.info("Temperature MAX31855 cmd: %s", " ".join(args))
+ proc = Popen(args, stdout=PIPE)
+ stdout, _ = proc.communicate()
+ if self._settings.get(["debug"]) is True and self._settings.get(["debug_temperature_log"]) is True:
+ self._logger.info("MAX31855 result: %s", stdout)
+ return self.to_float(stdout.strip())
+ except Exception as ex:
+ self._logger.info(
+ "Failed to excecute python scripts, try disabling use SUDO on advanced section.")
+ self.log_error(ex)
+ return 0
+
def handle_pwm_linked_temperature(self):
try:
for pwm_output in list(filter(lambda item: item['output_type'] == 'pwm' and item['pwm_temperature_linked'], self.rpi_outputs)):
diff --git a/octoprint_enclosure/max31855.py b/octoprint_enclosure/max31855.py
new file mode 100644
index 0000000..208d0f9
--- /dev/null
+++ b/octoprint_enclosure/max31855.py
@@ -0,0 +1,27 @@
+import ctypes
+import struct
+import sys
+
+import Adafruit_GPIO.SPI as SPI
+import Adafruit_MAX31855.MAX31855 as MAX31855
+
+
+def main():
+ # Get bus address if provided or use default address
+ SPI_DEVICE = 0
+ if len(sys.argv) >= 2:
+ SPI_DEVICE = int(sys.argv[1], 0)
+
+ if not 0 <= SPI_DEVICE <= 1:
+ raise ValueError("Invalid address value")
+
+ # Raspberry Pi hardware SPI configuration.
+ SPI_PORT = 0
+ sensor = MAX31855.MAX31855(spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE))
+
+ temp = sensor.readTempC()
+
+ print('{0:0.1f}'.format(temp))
+
+if __name__ == "__main__":
+ main()
diff --git a/octoprint_enclosure/templates/enclosure_settings.jinja2 b/octoprint_enclosure/templates/enclosure_settings.jinja2
index 97c05e5..9f60ed4 100644
--- a/octoprint_enclosure/templates/enclosure_settings.jinja2
+++ b/octoprint_enclosure/templates/enclosure_settings.jinja2
@@ -536,6 +536,7 @@
+
Attention You need to install and configure the necessary libraries for the temperature sensor, check
@@ -579,7 +580,30 @@
-
+
+
+
+
+
+ GPIO pin for temperature sensor need to connect the sensor to SPI. Serial Clock to GPIO 1 (SCLK) and Master In/Slave Out Data to GPIO
+ 9 (MISO)
+
+