Skip to content

Commit

Permalink
Merge pull request #78 from j7126/master
Browse files Browse the repository at this point in the history
DHT on PC and x86 fix
  • Loading branch information
StefanCohen committed Oct 7, 2019
2 parents 2b5d1ea + 84c2257 commit 06ac329
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
28 changes: 17 additions & 11 deletions octoprint_dashboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
from octoprint.util import RepeatedTimer
import re
import psutil
import Adafruit_DHT
import sys
import os
if sys.platform.startswith("linux"):
if os.uname()[1].startswith("octopi"):
import Adafruit_DHT

from octoprint.events import Events, eventManager

Expand All @@ -31,16 +35,18 @@ class DashboardPlugin(octoprint.plugin.SettingsPlugin,
dht_sensor_type = None

def adafruitDhtGetStats(self):
if self.dht_sensor_type == "DHT11":
sensor = Adafruit_DHT.DHT11
elif self.dht_sensor_type == "DHT22":
sensor = Adafruit_DHT.DHT22
else: return
pin = self.dht_sensor_pin
try:
self.ambient_humidity, self.ambient_temperature = Adafruit_DHT.read_retry(sensor, pin)
except RuntimeError as e:
print("Reading from DHT failure: ", e.args)
if sys.platform.startswith("linux"):
if os.uname()[1].startswith("octopi"):
if self.dht_sensor_type == "DHT11":
sensor = Adafruit_DHT.DHT11
elif self.dht_sensor_type == "DHT22":
sensor = Adafruit_DHT.DHT22
else: return
pin = self.dht_sensor_pin
try:
self.ambient_humidity, self.ambient_temperature = Adafruit_DHT.read_retry(sensor, pin)
except RuntimeError as e:
print("Reading from DHT failure: ", e.args)

def psUtilGetStats(self):
#temp_average = 0
Expand Down
10 changes: 9 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# coding=utf-8
import sys
import os

########################################################################################################################
### Do not forget to adjust the following variables to your own plugin.
Expand Down Expand Up @@ -33,7 +35,13 @@
plugin_license = "AGPLv3"

# Any additional requirements besides OctoPrint should be listed here
plugin_requires = ["psutil", "Adafruit_DHT"]
if sys.platform.startswith("linux"):
if os.uname()[1].startswith("octopi"):
plugin_requires = ["psutil", "Adafruit_DHT"]
else:
plugin_requires = ["psutil"]
else:
plugin_requires = ["psutil"]

### --------------------------------------------------------------------------------------------------------------------
### More advanced options that you usually shouldn't have to touch follow after this point
Expand Down

0 comments on commit 06ac329

Please sign in to comment.