From 2b5d1ea6614a43ffb3ae1dd695a63ff46eb4ec94 Mon Sep 17 00:00:00 2001 From: Stefan Cohen Date: Sun, 6 Oct 2019 20:33:36 +0200 Subject: [PATCH] Fix for #57 - raspberry temperature sensor (dht11) --- README.md | 2 +- octoprint_dashboard/__init__.py | 38 +++++++++++++++++- octoprint_dashboard/static/css/dashboard.css | 1 + .../static/img/ambient-sensor-icon.png | Bin 0 -> 1911 bytes octoprint_dashboard/static/js/dashboard.js | 7 +++- .../templates/dashboard_settings.jinja2 | 20 +++++++++ .../templates/dashboard_tab.jinja2 | 18 ++++++--- setup.py | 4 +- 8 files changed, 78 insertions(+), 12 deletions(-) create mode 100644 octoprint_dashboard/static/img/ambient-sensor-icon.png diff --git a/README.md b/README.md index 89fd65a..ece1e70 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ A dashboard tab for Octoprint that displays the most relevant info regarding the * RPi iost CPU Load, CPU Temp, Mem Utilization, Storage Utilization. * Printer profile, Connection status, Printer Status * Hotend temp(s), Bed Temp, Chamber Temp, Fan speed - * Printed file, Progress + * Printed file, Job Progress, Layer Progress * Layer Duration Graph * Estimated total time, ETA, Time left, Time since print started * Current layer, Total layers diff --git a/octoprint_dashboard/__init__.py b/octoprint_dashboard/__init__.py index fa1b994..4398917 100644 --- a/octoprint_dashboard/__init__.py +++ b/octoprint_dashboard/__init__.py @@ -4,6 +4,7 @@ from octoprint.util import RepeatedTimer import re import psutil +import Adafruit_DHT from octoprint.events import Events, eventManager @@ -24,6 +25,23 @@ class DashboardPlugin(octoprint.plugin.SettingsPlugin, layer_times = [] layer_labels = [] + ambient_humidity = 0 + ambient_temperature = 0 + dht_sensor_pin = 0 + 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) + def psUtilGetStats(self): #temp_average = 0 temp_sum = 0 @@ -38,13 +56,18 @@ def psUtilGetStats(self): self.virtual_memory_percent = str(psutil.virtual_memory().percent) self.disk_usage = str(psutil.disk_usage("/").percent) + # ~~ StartupPlugin mixin def on_after_startup(self): self._logger.info("Dashboard started") self.timer = RepeatedTimer(3.0, self.send_notifications, run_first=True) self.timer.start() + #Read settings + self.dht_sensor_pin = self._settings.get(["dhtSensorPin"]) + self.dht_sensor_type = self._settings.get(["dhtSensorType"]) def send_notifications(self): self.psUtilGetStats() + self.adafruitDhtGetStats() self._plugin_manager.send_plugin_message(self._identifier, dict(cpuPercent=str(self.cpu_percent), virtualMemPercent=str(self.virtual_memory_percent), diskUsagePercent=str(self.disk_usage), @@ -52,7 +75,9 @@ def send_notifications(self): extrudedFilament=str( round( (sum(self.extruded_filament_arr) + self.extruded_filament) / 1000, 2) ), layerTimes=str(self.layer_times), layerLabels=str(self.layer_labels), - printerMessage =str(self.printer_message))) + printerMessage =str(self.printer_message), + ambientHumidity = str(self.ambient_humidity), + ambientTemperature = str(self.ambient_temperature))) def on_event(self, event, payload): if event == "DisplayLayerProgress_layerChanged" or event == "DisplayLayerProgress_fanspeedChanged": @@ -103,9 +128,18 @@ def get_settings_defaults(self): showFullscreen=True, showFilament=True, showLayerGraph=False, - showPrinterMessage=False + showPrinterMessage=False, + showSensorInfo=False, + dhtSensorPin=4, + dhtSensorType=None ) + def on_settings_save(self, data): + octoprint.plugin.SettingsPlugin.on_settings_save(self, data) + self.dht_sensor_pin = self._settings.get(["dhtSensorPin"]) + self.dht_sensor_type = self._settings.get(["dhtSensorType"]) + + def get_template_configs(self): return [ dict(dict(type="tab", custom_bindings=False), type="settings", custom_bindings=False) ] diff --git a/octoprint_dashboard/static/css/dashboard.css b/octoprint_dashboard/static/css/dashboard.css index d2a0b63..bdf4fef 100644 --- a/octoprint_dashboard/static/css/dashboard.css +++ b/octoprint_dashboard/static/css/dashboard.css @@ -77,6 +77,7 @@ svg path { will-change: auto; stroke-width: 20px; stroke-miterlimit: round; + shape-rendering: auto; transition: stroke-dashoffset 500ms ease-in-out; } diff --git a/octoprint_dashboard/static/img/ambient-sensor-icon.png b/octoprint_dashboard/static/img/ambient-sensor-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..d896ee171cdc0592e0e47ae8593242015eaba383 GIT binary patch literal 1911 zcmV--2Z;EIP)^VB;IA68J$^JK;M6_CtB{Frp6XMiVpmQZ{Ku$p}=WGaoo?M&q@3aKH^ z$mTUB!(KgXC5a@q(&PBM*T^Pr2=Wx8VFwuE8D;_iFq3Bpg}q~xrw9`B_}Ih+$N7DO z#e}n%HyrP~z$SdeFiWX(98^2&n2vR{JKkT%Qeq9MyYaAt8K#63{u?QjFdQ~&T$GJSnTuhkDLC4sBiby6#$mgu%02;`}4Y@Qp{*ANb$7bF2epq)d`LG^)W2+v6 zlsW2dOzO@hQjcSfdMqOtdv#}zem!DecUCCWqe9)`Bo^z@Z(ny#tn1OQS9fiW1vQe( z|C3xA9dovkAIo(YgY_7Qc-=*+9s@*yjghar2-f39jk;Tp7VD!~k6Bbjq3$A6k5y#F za@}dwqe9)qKs{#js#4uWrXF7oEgVi{=QMc|C>hZ={sJkfCqmNmfLec;LPV)e*#21Ts zfgGmN&RsqZaUbEV;IG6V%Q;CnHAyTWk;zD+Uj8slqA)Dhn#4BB_y>nrNiT^)FDrSO zzfjJ1eF$_gKSB0@cUd4UNn+y#;053X;053X-~|u?Qt?^NAH~y z6E1R|?Ih!lJkD^LmzhsQ>5$LL%W=c5|BSlAUASS1%(o9$$X%YdNyD7w$UULRUIF<4 zz}39MwV1O;tblJ|&TMW20B+_5{r>_`EjEWjt8uW0t1#s~8pPM}1^ocZ=@5UA0H!ok zCBA?SnDYqZ;*aVFa7h*qv)F<;578!Gj5)_C6aN|uwF7`tRExWLEd2qy#qVI1tE+Ah z0Ps<)9{}tXo6r52^Bc}vUCaYiiErY1{Q!<}Mtn2ogs2eDbJZaggrt4GsUHA5Ep{tz zsA5oj3FdV1iepCA0P4i91H-Od0=~Mavz-qB$jA70fnE?Pya1?WVtP-!$ z48XaZYRmIjPaoziB@>xZKY;aQTAhyoo2Pg}FlPs8;@dH28SBM=#ar3|Y~u#; z5<-|Vmj}iFzzNLRB{nMIs|Aq3cJU?-V9pbyNCED^oK<{Typk^M03KzQ_zos9Wf7aj zU!uiD;qDS25LXLe4h7=1uJ-XV*~UI#C+2M6^WwYd(+*%KGpx3;<=iK}-$ilyDHZ=G zPlIj%H?u|jbxvAsV?&f;&K7PG|0yHd0ela?)i##HO7U`fFy~>hcc=pG0M>~8nl~|L ztymA`m@|(>;w6k}2QZgK;y<_iF(-pN#cM2Q{38?k0j#lH zPM#FtD7Bd5C(jw2W&n4J9l;IK4*(`;wS21EZ24Hb zMJ$6)>jwZ$Vk<4j-9Zp@dU;R$Zv6nDMeOT*%IXS8WsBvE59ozllfm1E}Tq;yGkt z${0UHU@hiU&@KKI{QzJy=Kz3Kx?OE(`^Ar9P7fR8X4oMMC%#G>;~b}g|Cvbrcsh%2Y{+1kkkteEbowIk<7q#Up&L8;v16P*P_Mz*#|yv< zzze_&zze_&zze_&zze_&zze_&zze_&zzaY~As$Kjr~uB3Eh8RT<~&mHBTz4oHXi2^ zwG0wJq>{_y$dTd%xR=QUdEJZPLjY>XC;mCY>gfWQM>FZfHv=r8bGjDjB!?5kGbhNQ x69Ie(63Ms8BZnLC5kE|Ffzur2mrNi4{2Rb)H!bbge^meg002ovPDHLkV1hakkB +
+ +
+ + Note! This is an experimental feature to support temperature/humidity sensors connected via RPi GPIO pins. + + +
+ +
+ +
+ +
diff --git a/octoprint_dashboard/templates/dashboard_tab.jinja2 b/octoprint_dashboard/templates/dashboard_tab.jinja2 index 31cc4f4..7d17d43 100644 --- a/octoprint_dashboard/templates/dashboard_tab.jinja2 +++ b/octoprint_dashboard/templates/dashboard_tab.jinja2 @@ -10,8 +10,7 @@
- +
@@ -23,6 +22,18 @@
+
+ +
+ + +
+
+
+
+
+
+
@@ -108,9 +119,6 @@ Job
- -       -
diff --git a/setup.py b/setup.py index 52ca626..ce3417a 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "OctoPrint-Dashboard" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "1.9.0" +plugin_version = "1.10.0" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module @@ -33,7 +33,7 @@ plugin_license = "AGPLv3" # Any additional requirements besides OctoPrint should be listed here -plugin_requires = ["psutil"] +plugin_requires = ["psutil", "Adafruit_DHT"] ### -------------------------------------------------------------------------------------------------------------------- ### More advanced options that you usually shouldn't have to touch follow after this point