Skip to content

Commit

Permalink
add again command that will print again the last file
Browse files Browse the repository at this point in the history
add fix for camera with new version
  • Loading branch information
giloser committed May 17, 2024
1 parent c3c1971 commit e1bd96c
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 41 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
This plugin integrates Telegram Messenger with Octoprint. It sends messages (with photos if available) on print start, end and failure. Also it sends messages during the print at configurable intervals. That way you don't have to remember to regularly have a look at the printing process.
Also, you can control Octoprint via messages (settings, start a print and much more). Send `/status` to get the current printer status or `/abort` to abort the current print. Send `/help` for a list of all recognized commands. You may also use this bot in groups.

**Latest release: [1.6.5](https://github.com/fabianonline/OctoPrint-Telegram/releases)**
**Latest release: [1.6.8](https://github.com/fabianonline/OctoPrint-Telegram/releases)**

<!-- omit in toc -->
## Contents
Expand Down Expand Up @@ -262,7 +262,7 @@ sudo apt-get install cpulimit
- the TuyaSmartplug plugin API. Requires the [TuyaSmartplug plugin](https://github.com/ziirish/OctoPrint-TuyaSmartplug/)
sadly for now wait on accept the push request to get the list of plug

**`/gcode`** - Send the gcode to the printer where XXX is the gcode command (/gcode_M117 HelloWorld for exemple)
**`/gcode_XXX`** - Send the gcode to the printer where XXX is the gcode command (/gcode_M117 HelloWorld for exemple)

<!-- omit in toc -->
#### Notes:
Expand Down
88 changes: 51 additions & 37 deletions octoprint_telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,9 +1753,11 @@ def _send_msg(
premethod = self._settings.get(["PreImgMethod"])
self._logger.debug("PreImgMethod {}".format(premethod))
precommand = self._settings.get(["PreImgCommand"])
doneprecommand = False
if premethod == "GCODE":
self._logger.debug("PreImgCommand {}".format(precommand))
self._printer.commands(precommand)
doneprecommand = True
elif premethod == "SYSTEM":
self._logger.debug("PreImgCommand {}".format(precommand))
p = subprocess.Popen(precommand, shell=True)
Expand All @@ -1769,10 +1771,18 @@ def _send_msg(
r = p.returncode
self._logger.debug(
"PreImg system command returned: {}".format(r)
)
doneprecommand = True

if doneprecommand:
precommanddelay = self._settings.get_int(["precommand_delay"])
if precommanddelay != None:
if precommanddelay > 0:
time.sleep(precommanddelay)

except Exception as ex:
self._logger.exception("Exception PreImgMethod: " + str(ex))

self._settings.get_int(["message_at_print_done_delay"])
if delay > 0:
time.sleep(delay)
try:
Expand Down Expand Up @@ -1982,15 +1992,10 @@ def _send_msg(
self._logger.debug("multicam_profiles : " + str(curr))
for li in curr:
try:
snapshot_url = li.get("snapshot") # try to get the snapshot url
self._logger.debug(
"multicam url : " + str(snapshot_url)
)

if not snapshot_url: # if snapshot url is not stored try to create it
self._logger.debug(
"multicam profile: " + str(li)
)
self._logger.debug("multicam profile: " + str(li))
snapshot_url = li.get("snapshot")
self._logger.debug("multicam snapshot : " + str(snapshot_url))
if(snapshot_url == "" or snapshot_url == "http://" or snapshot_url == "https://" or snapshot_url == None):
snapshot_url = li.get("URL")
self._logger.debug(
"multicam url : " + str(snapshot_url)
Expand Down Expand Up @@ -2177,6 +2182,12 @@ def _send_msg(

try:
if with_image or with_gif:
#delay
postcommanddelay = self._settings.get_int(["postcommand_delay"])
if postcommanddelay != None:
if postcommanddelay > 0:
time.sleep(postcommanddelay)

##find a way to decide if should and what command to light on
postmethod = self._settings.get(["PostImgMethod"])
self._logger.debug("PostImgMethod {}".format(postmethod))
Expand Down Expand Up @@ -2500,7 +2511,8 @@ def setMyCommands(self, force=False):
"description": "Makes the bot talk again (opposite of `/shutup`)",
}
)
commands.append(
commands.append({"command":"again","description":"Print again the same file"})
commands.append(
{"command": "help", "description": "Shows this help message"}
)
resp = requests.post(
Expand Down Expand Up @@ -2578,11 +2590,11 @@ def take_image(self, snapshot_url=""):
rotate = self._settings.global_get(["webcam", "rotate90"])
self._logger.debug(
"Image transformations [H:%s, V:%s, R:%s]", flipH, flipV, rotate
)
image = Image.open(bytes_reader_class(data))
if data == None:
return None
if flipH or flipV or rotate:
image = Image.open(bytes_reader_class(data))
if flipH:
image = image.transpose(Image.FLIP_LEFT_RIGHT)
if flipV:
Expand Down Expand Up @@ -2714,16 +2726,17 @@ def create_gif_new(self, chatID, sec=7, multicam_prof=0):
if self.TestProgram(["nice", "--version"]) > 0:
params = ["nice", "-n", "20"]

self._logger.info("test if cpulimit exist")
if self.TestProgram(["cpulimit", "--help"]) <= 0:
self._logger.info(
"cpulimit don't exist so send a message to install and exit"
)
self.send_msg(
self.gEmo("dizzy face")
+ " Problem creating gif, please check log file, and make sure you have installed cpulimit with following command : `sudo apt-get install cpulimit`",
chatID=chatID,
)
if(os.name != 'nt'):
self._logger.info("test if cpulimit exist")
if self.TestProgram(["cpulimit", "--help"]) <= 0:
self._logger.info(
"cpulimit don't exist so send a message to install and exit"
)
self.send_msg(
self.gEmo("dizzy face")
+ " Problem creating gif, please check log file, and make sure you have installed cpulimit with following command : `sudo apt-get install cpulimit`",
chatID=chatID,
)
return ""

self._logger.info("test if ffmpeg exist")
Expand Down Expand Up @@ -2788,20 +2801,21 @@ def create_gif_new(self, chatID, sec=7, multicam_prof=0):
"Caught an exception trying to get number of cpu : " + str(ex)
)

self._logger.info(
"limit_cpu="
+ str(limit_cpu)
+ " | used_cpu="
+ str(used_cpu)
+ " | because nb_cpu="
+ str(nb_cpu)
)
params.append("cpulimit")
params.append("-l")
params.append(str(limit_cpu))
params.append("-f")
params.append("-z")
params.append("--")
if(os.name != 'nt'):
self._logger.info(
"limit_cpu="
+ str(limit_cpu)
+ " | used_cpu="
+ str(used_cpu)
+ " | because nb_cpu="
+ str(nb_cpu)
)
params.append("cpulimit")
params.append("-l")
params.append(str(limit_cpu))
params.append("-f")
params.append("-z")
params.append("--")
params.append("ffmpeg")
params.append("-y")
params.append("-threads")
Expand Down
4 changes: 3 additions & 1 deletion octoprint_telegram/static/js/telegram.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,9 @@ $(function() {
var settings_to_check_number = [
settings.notification_height,
settings.notification_time,
settings.message_at_print_done_delay
settings.message_at_print_done_delay,
setting.precommand_delay,
setting.postcommand_delay
];
for (var i = 0; i < settings_to_check_number.length; i++) {
if (!self.isNumber(settings_to_check_number[i]())) {
Expand Down
19 changes: 19 additions & 0 deletions octoprint_telegram/telegramCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, main):
"/dontshutup": {"cmd": self.cmdNShutup},
"/print": {"cmd": self.cmdPrint, "param": True},
"/files": {"cmd": self.cmdFiles, "param": True},
"/again": {"cmd": self.cmdAgain, "param": True}, #giloser 16-10-2021
"/upload": {"cmd": self.cmdUpload},
"/filament": {"cmd": self.cmdFilament, "param": True},
"/sys": {"cmd": self.cmdSys, "param": True},
Expand Down Expand Up @@ -780,6 +781,24 @@ def cmdUpload(self, chat_id, from_id, cmd, parameter, user = ""):
chatID=chat_id,
)

############################################################################################
def cmdAgain(self,chat_id,from_id,cmd,parameter):
try:
data = self.main._printer.get_current_data()
if self.main._printer.is_printing():
self.main.send_msg(self.gEmo("warning") + " A print job is already running. You can"t print two thing at the same time. Maybe you want to use /abort?",chatID=chat_id)#, msg_id = self.main.getUpdateMsgId(chat_id))
elif not self.main._printer.is_operational():
self.main.send_msg(self.gEmo("warning") + gettext(" Can"t start printing: I"m not connected to a printer."),chatID=chat_id)#, msg_id = self.main.getUpdateMsgId(chat_id))
elif data["job"]["file"]["name"] is not None:
file = data["job"]["file"]["name"]
msg = self.gEmo("info") + gettext(" The file " +str(file)+" is loaded.\n\n"+self.gEmo("question")+" Do you want me to start printing it now?", file=data["job"]["file"]["name"])
self.main.send_msg(msg,noMarkup=True, responses=[[[self.main.emojis["check"]+gettext("Print"),"/print_s"], [self.main.emojis["cross mark"]+gettext(" Cancel"),"/print_x"]]],chatID=chat_id)#, msg_id = self.main.getUpdateMsgId(chat_id))
else:
self.main.send_msg(self.gEmo("warning") + gettext(" File not loaded. Please use this after another print."),chatID=chat_id)#, msg_id = self.main.getUpdateMsgId(chat_id))
except Exception as e:
self._logger.warn("Command failed: %s" % e)
self.main.send_msg(self.gEmo("warning") + " Command failed with exception: %s!" % e,chatID = chat_id)#, msg_id = self.main.getUpdateMsgId(chat_id))

############################################################################################
def cmdSys(self, chat_id, from_id, cmd, parameter, user = ""):
if parameter and parameter != "back":
Expand Down
8 changes: 8 additions & 0 deletions octoprint_telegram/templates/telegram_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@
</select>
<span class="help-block"><small>Action pre image could be none, a gcode or a system command (script name with full path)</small></span>
<input type="text" class="input-block-level" id="settings_plugin_telegram_PreImgCommand" data-bind="value: settings.settings.plugins.telegram.PreImgCommand"/>

<input type="number" step="any" min="0.0" class="input-mini text-right" data-bind="value: settings.settings.plugins.telegram.precommand_delay" />
<span class="add-on">s</span>
<span class="help-block"><small>Wait this many seconds after pre image action. Set to 0 to disable.</small></span>
</div>
</div>

Expand All @@ -263,6 +267,10 @@
</select>
<span class="help-block"><small>Action post image could be none, a gcode or a system command (script name with full path)</small></span>
<input type="text" class="input-block-level" id="settings_plugin_telegram_PostImgCommand" data-bind="value: settings.settings.plugins.telegram.PostImgCommand" />

<input type="number" step="any" min="0.0" class="input-mini text-right" data-bind="value: settings.settings.plugins.telegram.postcommand_delay" />
<span class="add-on">s</span>
<span class="help-block"><small>Wait this many seconds before post image action. Set to 0 to disable.</small></span>
</div>
</div>

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-Telegram"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "1.6.7"
plugin_version = "1.6.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 e1bd96c

Please sign in to comment.