Skip to content

Commit

Permalink
0.8.8
Browse files Browse the repository at this point in the history
- Added thermal runaway options
- Disable powering off plug on gcode off command if printer is printing and warn while printing option is enabled
  • Loading branch information
jneilliii authored Dec 2, 2019
1 parent 568eafd commit ec9306a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 7 deletions.
45 changes: 41 additions & 4 deletions octoprint_tasmota/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class tasmotaPlugin(octoprint.plugin.SettingsPlugin,
def __init__(self):
self._logger = logging.getLogger("octoprint.plugins.tasmota")
self._tasmota_logger = logging.getLogger("octoprint.plugins.tasmota.debug")
self.thermal_runaway_triggered = False

##~~ StartupPlugin mixin

Expand All @@ -45,7 +46,10 @@ def get_settings_defaults(self):
debug_logging = False,
polling_enabled = False,
polling_interval = 0,
arrSmartplugs = [{'ip':'','displayWarning':True,'idx':'1','warnPrinting':False,'gcodeEnabled':False,'gcodeOnDelay':0,'gcodeOffDelay':0,'autoConnect':True,'autoConnectDelay':10.0,'autoDisconnect':True,'autoDisconnectDelay':0,'sysCmdOn':False,'sysRunCmdOn':'','sysCmdOnDelay':0,'sysCmdOff':False,'sysRunCmdOff':'','sysCmdOffDelay':0,'currentState':'unknown','username':'admin','password':'','icon':'icon-bolt','label':'','on_color':'#00FF00','off_color':'#FF0000','unknown_color':'#808080','use_backlog':False,'backlog_on_delay':0,'backlog_off_delay':0}],
thermal_runaway_monitoring = False,
thermal_runaway_max_bed = 120,
thermal_runaway_max_extruder = 300,
arrSmartplugs = [{'ip':'','displayWarning':True,'idx':'1','warnPrinting':False,'gcodeEnabled':False,'gcodeOnDelay':0,'gcodeOffDelay':0,'autoConnect':True,'autoConnectDelay':10.0,'autoDisconnect':True,'autoDisconnectDelay':0,'sysCmdOn':False,'sysRunCmdOn':'','sysCmdOnDelay':0,'sysCmdOff':False,'sysRunCmdOff':'','sysCmdOffDelay':0,'currentState':'unknown','username':'admin','password':'','icon':'icon-bolt','label':'','on_color':'#00FF00','off_color':'#FF0000','unknown_color':'#808080','use_backlog':False,'backlog_on_delay':0,'backlog_off_delay':0,'thermal_runaway':False}]
)

def on_settings_save(self, data):
Expand All @@ -61,7 +65,7 @@ def on_settings_save(self, data):
self._tasmota_logger.setLevel(logging.INFO)

def get_settings_version(self):
return 4
return 5

def on_settings_migrate(self, target, current=None):
if current is None or current < self.get_settings_version():
Expand Down Expand Up @@ -210,6 +214,16 @@ def on_api_command(self, command, data):

##~~ Gcode processing hook

def gcode_off(self, plug):
if plug["warnPrinting"] and self._printer.is_printing():
self._tasmota_logger.info("Not powering off %s because printer is printing." % plug["label"])
else:
self.turn_off(plug["ip"], plug["idx"], username = plug["username"], password = plug["password"], backlog_delay = plug["backlog_on_delay"])

def gcode_on(self, plug):
self.turn_on(plug["ip"], plug["idx"], username = plug["username"], password = plug["password"], backlog_delay = plug["backlog_on_delay"])


def processGCODE(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs):
if gcode:
if cmd.startswith("M8") and cmd.count(" ") >= 2:
Expand All @@ -221,22 +235,44 @@ def processGCODE(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwar
if plug["sysCmdOn"] and plug["sysRunCmdOn"] != "":
s = threading.Timer(int(plug["sysCmdOnDelay"]), os.system, [plug["sysRunCmdOn"]])
s.start()
t = threading.Timer(int(plug["gcodeOnDelay"]),self.turn_on, [plug["ip"],plug["idx"]],{'username': plug["username"],'password': plug["password"],'backlog_delay': plug["backlog_on_delay"]})
t = threading.Timer(int(plug["gcodeOnDelay"]),self.gcode_on, [plug])
t.start()
self._tasmota_logger.debug("Received M80 command, attempting power on of %s index %s." % (plugip,plugidx))
return
elif cmd.startswith("M81"):
if plug["sysCmdOff"] and plug["sysRunCmdOff"] != "":
s = threading.Timer(int(plug["sysCmdOffDelay"]), os.system, [plug["sysRunCmdOff"]])
s.start()
t = threading.Timer(int(plug["gcodeOffDelay"]),self.turn_off, [plug["ip"],plug["idx"]],{'username': plug["username"],'password': plug["password"],'backlog_delay': plug["backlog_off_delay"]})
t = threading.Timer(int(plug["gcodeOffDelay"]),self.gcode_off, [plug])
t.start()
self._tasmota_logger.debug("Received M81 command, attempting power off of %s index %s." % (plugip,plugidx))
return
else:
return
return

##~~ Temperatures received hook

def check_temps(self, parsed_temps):
for k, v in parsed_temps.items():
if k == "B" and v[0] > int(self._settings.get(["thermal_runaway_max_bed"])):
self._tasmota_logger.debug("Max bed temp reached, shutting off plugs.")
self.thermal_runaway_triggered = True
if k.startswith("T") and v[0] > int(self._settings.get(["thermal_runaway_max_extruder"])):
self._tasmota_logger.debug("Extruder max temp reached, shutting off plugs.")
self.thermal_runaway_triggered = True
if self.thermal_runaway_triggered == True:
for plug in self._settings.get(['arrSmartplugs']):
if plug["thermal_runaway"] == True:
self.turn_off(plug["ip"],plug["idx"],username = plug["username"], password = plug["password"], backlog_delay = plug["backlog_off_delay"])

def monitor_temperatures(self, comm, parsed_temps):
if self._settings.get(["thermal_runaway_monitoring"]) and self.thermal_runaway_triggered == False:
# Run inside it's own thread to prevent communication blocking
t = threading.Timer(0,self.check_temps,[parsed_temps])
t.start()
return parsed_temps


##~~ Softwareupdate hook

Expand Down Expand Up @@ -274,6 +310,7 @@ def __plugin_load__():
global __plugin_hooks__
__plugin_hooks__ = {
"octoprint.comm.protocol.gcode.queuing": __plugin_implementation__.processGCODE,
"octoprint.comm.protocol.temperatures.received": __plugin_implementation__.monitor_temperatures,
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
}

3 changes: 2 additions & 1 deletion octoprint_tasmota/static/js/tasmota.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ $(function() {
'unknown_color':ko.observable('#808080'),
'use_backlog':ko.observable(false),
'backlog_on_delay':ko.observable(0),
'backlog_off_delay':ko.observable(0)});
'backlog_off_delay':ko.observable(0),
'thermal_runaway':ko.observable(false)});
self.settings.settings.plugins.tasmota.arrSmartplugs.push(self.selectedPlug());
$("#TasmotaEditor").modal("show");
}
Expand Down
21 changes: 20 additions & 1 deletion octoprint_tasmota/templates/tasmota_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<td style="text-align:center">
<i class="icon" data-bind="css: {'icon-check': displayWarning(),'icon-check-empty': !displayWarning()}" title="Warning Prompt" />
<i class="icon" data-bind="css: {'icon-check': warnPrinting(),'icon-check-empty': !warnPrinting()}" title="Warn While Printing" />
<i class="icon" data-bind="css: {'icon-check': thermal_runaway(),'icon-check-empty': !thermal_runaway()}" title="Thermal Runaway" />
<i class="icon" data-bind="css: {'icon-check': autoConnect(),'icon-check-empty': !autoConnect()}" title="Auto Connect" />
<i class="icon" data-bind="css: {'icon-check': autoDisconnect(),'icon-check-empty': !autoDisconnect()}" title="Auto Disconnect" />
<i class="icon" data-bind="css: {'icon-check': gcodeEnabled(),'icon-check-empty': !gcodeEnabled()}" title="GCODE Trigger" />
Expand All @@ -31,6 +32,24 @@
</tbody>
</table>

<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.settings.plugins.tasmota.thermal_runaway_monitoring" /> Enable thermal runaway monitoring.
</label>
</div>
</div>
<div class="control-group" data-bind="visible: settings.settings.plugins.tasmota.thermal_runaway_monitoring">
<div class="controls">
<label class="control-label">{{ _('Max Bed Temp') }}</label>
<input type="number" min="0" class="input input-small" data-bind="value: settings.settings.plugins.tasmota.thermal_runaway_max_bed" />
</div>
<div class="controls">
<label class="control-label">{{ _('Max Extruder Temp') }}</label>
<input type="number" min="0" class="input input-small" data-bind="value: settings.settings.plugins.tasmota.thermal_runaway_max_extruder" />
</div>
</div>

<div class="control-group">
<div class="controls">
<label class="checkbox">
Expand Down Expand Up @@ -94,7 +113,7 @@
<tr>
<td><div class="controls"><label class="checkbox"><input type="checkbox" data-bind="checked: displayWarning"/> Warning Prompt</label></div></td>
<td><div class="controls"><label class="checkbox"><input type="checkbox" data-bind="checked: warnPrinting"/> Warn While Printing</label></div></td>
<td></td>
<td><div class="controls"><label class="checkbox"><input type="checkbox" data-bind="checked: thermal_runaway"/> Thermal Runaway</label></div></td>
</tr>
<tr>
<td><div class="controls"><label class="checkbox"><input type="checkbox" data-bind="checked: autoConnect"/> Auto Connect</label><input type="text" data-bind="value: autoConnectDelay,visible: autoConnect" class="input input-small" /></div></td>
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "OctoPrint-Tasmota"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "0.8.7"
plugin_version = "0.8.8"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit ec9306a

Please sign in to comment.