Skip to content

Commit

Permalink
Fix for #57 - raspberry temperature sensor (dht11)
Browse files Browse the repository at this point in the history
  • Loading branch information
sco01 committed Oct 6, 2019
1 parent 89ad8e0 commit 2b5d1ea
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 36 additions & 2 deletions octoprint_dashboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from octoprint.util import RepeatedTimer
import re
import psutil
import Adafruit_DHT

from octoprint.events import Events, eventManager

Expand All @@ -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
Expand All @@ -38,21 +56,28 @@ 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),
cpuTemp=str(self.cpu_temp),
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":
Expand Down Expand Up @@ -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) ]
Expand Down
1 change: 1 addition & 0 deletions octoprint_dashboard/static/css/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions octoprint_dashboard/static/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@ $(function () {
self.lastLayerDuration = ko.observable("-");
self.averageLayerDuration = ko.observable("-");

//Dashboard backend vars
self.getEta = ko.observable();
self.embedUrl = ko.observable("");
self.extrudedFilament = ko.observable(0.00);
self.layerProgressString = ko.observable(0);
self.layerProgressBarString = ko.observable("0%");
self.printerMessage = ko.observable("");

//Dashboard backend vars
self.cpuPercent = ko.observable(0);
self.virtualMemPercent = ko.observable(0);
self.diskUsagePercent = ko.observable(0);
self.cpuTemp = ko.observable(0);
self.ambientTemperature = ko.observable(0);
self.ambientHumidity = ko.observable(0);

//Fullscreen
self.urlParams = new URLSearchParams(window.location.search);
Expand Down Expand Up @@ -260,6 +261,8 @@ $(function () {
if (data.cpuTemp) { self.cpuTemp(data.cpuTemp); }
if (data.printerMessage) { self.printerMessage(data.printerMessage); }
if (data.extrudedFilament) { self.extrudedFilament(data.extrudedFilament); }
if (data.ambientTemperature) { self.ambientTemperature(data.ambientTemperature); }
if (data.ambientHumidity) { self.ambientHumidity(data.ambientHumidity); }
if (data.layerTimes && data.layerLabels) { self.renderChart(data.layerTimes, data.layerLabels); }
}
};
Expand Down
20 changes: 20 additions & 0 deletions octoprint_dashboard/templates/dashboard_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
<input type="checkbox" data-bind="checked: settings.plugins.dashboard.showSystemInfo">
</label>
</div>
<div >
<label class="checkbox">{{ _('Show Sensor Info (Experimental)') }}
<input type="checkbox" data-bind="checked: settings.plugins.dashboard.showSensorInfo">
</label>
</div>
<div >
<label class="checkbox">{{ _('Show Fan Gauge') }}
<input type="checkbox" data-bind="checked: settings.plugins.dashboard.showFan">
Expand Down Expand Up @@ -95,6 +100,21 @@
<input type="checkbox" data-bind="checked: settings.plugins.dashboard.hideHotend">
</label>
</div>
<span class="help-inline">
<span class="label label-important">Note!</span> This is an experimental feature to support temperature/humidity sensors connected via RPi GPIO pins.
</span>
<label class="control-label">{{ _('DHT Sensor Pin:')}}</label>
<div class="controls">
<input type="number" min="0" max="50" step="1" class="input-mini text-left" data-bind="value: settings.plugins.dashboard.dhtSensorPin">
</div>
<label class="control-label">{{ _('DHT Sensor Type') }}</label>
<div class="controls">
<select data-bind="value: settings.plugins.dashboard.dhtSensorType">
<option value="">Select Sensor</option>
<option value="DHT11">DHT11</option>
<option value="DHT22">DHT22</option>
</select>
</div>
</div>
</form>

Expand Down
18 changes: 13 additions & 5 deletions octoprint_dashboard/templates/dashboard_tab.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<img class="dashboardIcon" title="CPU Usage" src="plugin/dashboard/static/img/cpu-icon.png">
<div class="inline">
<span id="profileInfo" data-bind="attr: { title: 'CPU Usage' }, html: cpuPercent() + '%'"></span>
<span class="dashboardSmall" id="cpuTemp"
data-bind="attr: { title: 'CPU Temperature' }, html: cpuTemp() + '°C'"></span>
<span class="dashboardSmall" id="cpuTemp" data-bind="attr: { title: 'CPU Temperature' }, html: cpuTemp() + '°C'"></span>
</div>
</div>
<div class="dashboardGridItem" data-bind="visible: settingsViewModel.settings.plugins.dashboard.showSystemInfo()">
Expand All @@ -23,6 +22,18 @@
<span id="stateInfo" data-bind="attr: { title: 'Disk Usage' }, html: diskUsagePercent() + '%'"></span>
</div>

<div class="dashboardGridItem" data-bind="visible: settingsViewModel.settings.plugins.dashboard.showSystemInfo() && settingsViewModel.settings.plugins.dashboard.showSensorInfo()">
<img class="dashboardIcon" title="Ambient Sensor" src="plugin/dashboard/static/img/ambient-sensor-icon.png">
<div class="inline">
<span id="TempSensorInfo" data-bind="attr: { title: 'Ambient Temp Sensor' }, html: ambientTemperature() + '°C'"></span>
<span class="dashboardSmall" id="HumiditySensorInfo" data-bind="attr: { title: 'Ambient Humidity Sensor' }, html: ambientHumidity() + '%'"></span>
</div>
</div>
<div class="dashboardGridItem" data-bind="visible: settingsViewModel.settings.plugins.dashboard.showSystemInfo() && settingsViewModel.settings.plugins.dashboard.showSensorInfo()">
</div>
<div class="dashboardGridItem" data-bind="visible: settingsViewModel.settings.plugins.dashboard.showSystemInfo() && settingsViewModel.settings.plugins.dashboard.showSensorInfo()">
</div>

<!-- Current Profile, Connection state, and current status-->
<div class="dashboardGridItem">
<img class="dashboardIcon" title="Printer profile" src="plugin/dashboard/static/img/printer-icon.png">
Expand Down Expand Up @@ -108,9 +119,6 @@
<text class="dashboardGauge" font-size="14" x="50%" y="65%" dominant-baseline="middle" text-anchor="middle" fill="#08c">Job</text>
</svg>
</div>

<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>

<!-- Layer Progress Circle-->
<div class="dashboardProgressContainer dashboardLayerProgressContainer" data-bind="visible: printerStateModel.isPrinting() && settingsViewModel.settings.plugins.dashboard.showLayerProgress() && (settingsViewModel.settings.plugins.dashboard.gaugetype() == 'circle'), DashboardContextMenu: jobMenu, css: { dashboardLayerProgressInline: settingsViewModel.settings.plugins.dashboard.showProgress() && settingsViewModel.settings.plugins.dashboard.showLayerProgress() }">
<svg class="current" width="120" height="120" viewBox="0 0 120 120">
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2b5d1ea

Please sign in to comment.