Coder Social home page Coder Social logo

nlef / moonraker-telegram-bot Goto Github PK

View Code? Open in Web Editor NEW
241.0 10.0 63.0 865 KB

Telegram bot to interact with Moonraker (Klipper Web API Server)

License: Creative Commons Zero v1.0 Universal

Shell 5.08% Python 94.20% Dockerfile 0.72%
telegram-bot moonraker klipper

moonraker-telegram-bot's Introduction

moonraker-telegram-bot

image

The general idea of this project is to provide you with a way to control and monitor your printer without having to setup a vpn, opening your home network, or doing any sort of other network-related vodoo. In addition you get the benefits of push-style notifications always in your pocket, and a bandwidth-friendly way to check up on your print progress, when not near the printer.

As always with solutions like these, we kindly remind you not to print unattended, and always to take all necessary precautions against fire hazards.

Features and Installation:

Please check out our wiki for installation instructions and detailed feature descriptions.

Issues and bug reports

We will be happy to assist you with any issues that you have, as long as you can form a coherent sentence and are polite in your requests. Please open an issue, and we will try our best to reproduce and fix it. Feature requests and ideas are also more than welcome.

When writing issues/contacting for support please attach the 'telegram.log' as well as the output of sudo journalctl -r -u moonraker-telegram-bot.

Happy Printing!

Donate


Klipper by KevinOConnor :

https://github.com/KevinOConnor/klipper


Moonraker by Arksine :

https://github.com/Arksine/moonraker


KIAUH - Klipper Installation And Update Helper by th33xitus :

https://github.com/th33xitus/KIAUH


Mainsail Webinterface by meteyou :

https://github.com/meteyou/mainsail


Fluidd Webinterface by cadriel :

https://github.com/cadriel/fluidd


moonraker-telegram-bot's People

Contributors

aka13-404 avatar dxcx avatar kapji avatar leshe4ka46 avatar mkuf avatar nlef avatar pidpawel avatar reijii-fpv avatar rushonline avatar suglosta avatar xyzroe avatar zergo0 avatar zztopper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

moonraker-telegram-bot's Issues

Add video to status update

rather than (or in addition to) sending the same picture of the sliced thumbnail for each status up[date, can we get pictures or videos of the printer during status updates?

Alternative triggers for timelapse start and end

Since the priting is often done, before service operations take place (i.e. moving the table on bedslinger printers forward), it might be a good idea to be able to define alternative endpoints for the timelapse feature of the bot.

Also, since before the print some service operations, like a prime line, may take place, a alternative starting point for the timelapse might be interesting.

In addition, a timelapse pause function, for filament or toolchanges might be of value.

I suggest using klipper macros, specifically the RESPOND MSG G-Code.
RESPOND PREFIX=timelapse MSG=start. RESPOND PREFIX=timelapse MSG=stop, RESPOND PREFIX=timelapse MSG=pause, RESPOND PREFIX=timelapse MSG=continue respectively.

High CPU usage causes mcu shutdown timer too close

Hi, I'm using the latest version of fluiddpi with fluidd, moonraker and klipper all updated on a Raspberry Pi Zero 2. The printer is an Eryone Thinker S with an ATmega2560 based motherboard. I've had no problems until I installed the Telegram bot. During prints, I see high cpu usage by the bot process, it uses completely one of the four cores of the raspy, causing the print to fail after some time for timer errors with the mcu. In fluidd, I see an average of host cpu usage over 1.00, that falls rapidly around 0.20 if I stop the bot. In the bot's config, I enabled the notifications during the print only every 25% of completion and I included the temperatures of hotend and bed, no camera, timelapse or other functions. Is the high cpu usage normal? I'm here to help to diagnose the problem, if you need. Thank you!

Alternative status messages via message pins/edits

A good addition would be to add a mode, where the bot does not send new status message for each update, but rather pins/edits a single message, which prevents notification spam, and allows the user to get more frequent, easier to track notifications, without getting spam in the bot chat.

This should be an option to default new status-new message approach.
Additional thing to consider would be how this behaves with bot-groups.

./install.sh doesn't work..

my problem is.. I deleted by mistake parts of the code... I tried to delete everything an tried to install it again.. but.. all I get is the following message:
./install.sh
Stopping moonraker-telegram-bot instance ...
Failed to stop moonraker-telegram-bot.service: Unit moonraker-telegram-bot.service not loaded.

I have no idea what to do.. I hope you can help me solving the problem because I love your bot

btw.. the Logfile has no entries..

Latest commit breaks the bot

Just make a git pull and restarted service

May 02 19:44:30 voron2 python[20020]: 2021-05-02 19:44:30,000 - apscheduler.scheduler - INFO - Scheduler started
May 02 19:44:48 voron2 python[20020]: 2021-05-02 19:44:48,746 - telegram.ext.dispatcher - ERROR - No error handlers are registered, logging exception.
May 02 19:44:48 voron2 python[20020]: Traceback (most recent call last):
May 02 19:44:48 voron2 python[20020]:   File "/home/pi/moonraker-telegram-bot-env/lib/python3.7/site-packages/telegram/ext/dispatcher.py", line 442, in process_update
May 02 19:44:48 voron2 python[20020]:     handler.handle_update(update, self, check, context)
May 02 19:44:48 voron2 python[20020]:   File "/home/pi/moonraker-telegram-bot-env/lib/python3.7/site-packages/telegram/ext/handler.py", line 160, in handle_update
May 02 19:44:48 voron2 python[20020]:     return self.callback(update, context)
May 02 19:44:48 voron2 python[20020]:   File "/home/pi/moonraker-telegram-bot/main.py", line 138, in status
May 02 19:44:48 voron2 python[20020]:     message_to_reply.reply_text(get_status())
May 02 19:44:48 voron2 python[20020]:   File "/home/pi/moonraker-telegram-bot/main.py", line 114, in get_status
May 02 19:44:48 voron2 python[20020]:     light_status = get_light_status()
May 02 19:44:48 voron2 python[20020]:   File "/home/pi/moonraker-telegram-bot/main.py", line 128, in get_light_status
May 02 19:44:48 voron2 python[20020]:     response = urllib.request.urlopen(f"http://{host}/machine/device_power/status?{light_device}")
May 02 19:44:48 voron2 python[20020]:   File "/usr/lib/python3.7/urllib/request.py", line 222, in urlopen
May 02 19:44:48 voron2 python[20020]:     return opener.open(url, data, timeout)
May 02 19:44:48 voron2 python[20020]:   File "/usr/lib/python3.7/urllib/request.py", line 531, in open
May 02 19:44:48 voron2 python[20020]:     response = meth(req, response)
May 02 19:44:48 voron2 python[20020]:   File "/usr/lib/python3.7/urllib/request.py", line 641, in http_response
May 02 19:44:48 voron2 python[20020]:     'http', request, response, code, msg, hdrs)
May 02 19:44:48 voron2 python[20020]:   File "/usr/lib/python3.7/urllib/request.py", line 569, in error
May 02 19:44:48 voron2 python[20020]:     return self._call_chain(*args)
May 02 19:44:48 voron2 python[20020]:   File "/usr/lib/python3.7/urllib/request.py", line 503, in _call_chain
May 02 19:44:48 voron2 python[20020]:     result = func(*args)
May 02 19:44:48 voron2 python[20020]:   File "/usr/lib/python3.7/urllib/request.py", line 649, in http_error_default
May 02 19:44:48 voron2 python[20020]:     raise HTTPError(req.full_url, code, msg, hdrs, fp)
May 02 19:44:48 voron2 python[20020]: urllib.error.HTTPError: HTTP Error 404: Not Found
May 02 19:46:39 voron2 systemd[1]: Stopping Starts Moonraker Telegram Bot on startup...

Execute gcode after creating timelapse

Возможно не помешает добавить возможность исполнения какого-то gcode после того как собрался таймлапс

No timelapse at end

Had a print recently end and instead of a time-lapse video I got this message...

Images recoded 1380/3321

Any ideas?

Feature: option to send messages from macro

I'm looking for a way to get a message when my filament runout, filament change macro is running or any other message I think is important for me to know

In my macros I have M117 messages so one way to have an option to get every M117 message per notification.
Any other option is me good aswell.
I just want manual send important notifications.

File is too big

При загрузке больших файлов gcode (например 60Мб) загрузка файла не происходит.
В логе
2021-06-18 15:42:15,093 - __main__ - ERROR - Exception while handling an update: Traceback (most recent call last): File "/home/pi/moonraker-telegram-bot-env/lib/python3.7/site-packages/telegram/ext/utils/promise.py", line 96, in run self._result = self.pooled_function(*self.args, **self.kwargs) File "/home/pi/moonraker-telegram-bot/main.py", line 364, in upload_file bio.write(doc.get_file().download_as_bytearray()) File "/home/pi/moonraker-telegram-bot-env/lib/python3.7/site-packages/telegram/files/document.py", line 125, in get_file return self.bot.get_file(file_id=self.file_id, timeout=timeout, api_kwargs=api_kwargs) File "/home/pi/moonraker-telegram-bot-env/lib/python3.7/site-packages/telegram/bot.py", line 129, in decorator result = func(*args, **kwargs) File "/home/pi/moonraker-telegram-bot-env/lib/python3.7/site-packages/telegram/bot.py", line 2293, in get_file result = self._post('getFile', data, timeout=timeout, api_kwargs=api_kwargs) File "/home/pi/moonraker-telegram-bot-env/lib/python3.7/site-packages/telegram/bot.py", line 295, in _post f'{self.base_url}/{endpoint}', data=data, timeout=effective_timeout File "/home/pi/moonraker-telegram-bot-env/lib/python3.7/site-packages/telegram/utils/request.py", line 361, in post **urlopen_kwargs, File "/home/pi/moonraker-telegram-bot-env/lib/python3.7/site-packages/telegram/utils/request.py", line 279, in _request_wrapper raise BadRequest(message) telegram.error.BadRequest: File is too big

Сам бот об ошибке не сообщает.

Add config checks before initialisation

The bot should crash and or inform the user about wrong config lines, or ignored config lines.
It would be also good, to warn the user on startup about depreciated features.

Get Notification when printer shutdown

It would be great if I get an notification when the printer was shutdown because of emergency.

Today I got a problem with on step stick and got no notification about it.

image

No-camera mode

The bot can be useful even without a camera attached, for buttons, macros, status changes, etc.
It should be checked, how the bot behaves without the camera, and adjust specific featuresets if no camera is specified
(/video, /photo, timelapsing etc should be removed)

[request] FFMPEG

Hallo, is it possible to add extra parameters to FFMPEG in the config like -c:v h264_nvmpi ???

Im running a Jetson Nano and it should be fun to use Cuda core instead of CPU power.

Best

Notification problem

For some time now, I have had a problem with notifications while printing, they stopped coming. Timelaps is also not working. The bot_restart command is not working.

telegram.log

moonraker authorization

При добавлении пользователей через fluidd и установке в mooraker.conf:

[authorization]
force_logins: true

бот не будет работать.
Прошу добавить авторизацию бота в moonraker по логину/паролю.

Consistent config format between

It might make sense to unify the configuration format with klipper and moonraker.

The current config format is not unified with klipper, which might lead to user input errors and undesired behaviour.

timelapse {
heigth = 0
enabled = true
}

The config in example for the timelapse module uses curved brackets, tabulation and the ability to disable a featur by setting a
"enabled = true" flag.

With klipper and moonraker, a feature is enabled by having it present in the config in square brackets, i.e.:

[display_status]
[pause_resume]

The disabling of a feature is simply omitting it from the config alltogether.
Parameters are set to 0 per default, and unless entered into the config are inactive, as in

[stepper_x]
gear_ratio: 5:1

Unless gear ratio is present in the config, it is set to 0 and not used.

Referring to the initial example with the timelapse module of the bot,
it should look like this:
[timelapse]
#height: 0.2

It should be considered, that should this change be implemented, it will break backwards compatibility with existing installations. Nevertheless, in my opinion, it is urgently needed to make this change while the userbase is small, and the available features are minimal.

Input from @zztopper as well as @suglosta and @RushOnline is more than welcome.

Add the possibility to run G-Codes or call a macro when the timelapse video is composed.

If the timelapse video is greater than 50mb, it's not possible for bot to send it to telegram chat.
So that's why I want to send it to an external storage (cloud/local webserver, youtube etc) via shell script.
Shell script would take the timelapse file name with full path as an input parameter, and return the URL of the uploaded video, so that the bot could send the URL to the chat.

Sending timelapse video to the telegram chat as it is now should be optional, controlled with a param.
If the script name variable is not empty, script should be run after timelapse video is composed.

Add confirmation on runtime parameter change

Right now there is no feedback, if a runtime change happened successfully.
This may lead to undesired results after a print due to typos.

A short response, that changes applied succesfully should be sent to the user.

mistype reponse -> response

Found a mistype in bot/main.py:

def status_reponse(message_result):
def notify_gcode_reponse(message_params):

I believe there should be response instead of reponse

Change manual timelapse mode behaviour for pause&resume

As discussed, the proposed change would be to allow manual capturing with RESPOND PREFIX=timelapse MSG=photo while the timelapse is set to "pause". This would allow to subtly influence the behaviour in needed places, like the end of a print, together with the new closing picture feature.

The suggested cahnges would mean:

  • timelapse stop completely stops lapsing functionality for the current print. Only timelapse create is available.
  • timelapse pause pauses any automated lapsing features, as time, layer or percentage based, but allows manual capture
  • timelapse resume resumes automated lapsing

directory change on last update?

My bot was working great until a moonraker update the other night. I have this repo set as documented to pull updates as well. it all updated so I am not sure which one of the things broke this.

It no longer responds.

I ran journalctl and found that its looking for:

Sep 17 22:08:28 fluiddpi python[925]: /home/pi/moonraker-telegram-bot-env/bin/python: can't open file '/home/pi/moonraker-telegram-bot/main.py': [Errno 2] No such file or directory

but in fact that file is located in

/home/pi/moonraker-telegram-bot/bot/main.py

I didn't change anything here.
Any thoughts?

Support for 1+ video inputs

A good feature would be to be able to use multiple webcams/video inputs simultaneously.
Potentially that would mean, that every /status, /video, etc captures 2 inputs, and these get grouped as albums and are sent together.

Option to config /status response

When you do /status you get the following output:

image

It would be nice to define that layout in the telegram.conf. Personally, I don't care about the filament usage and weight of the part (already checked in the slicer). I'm more interested in the layer height of the part, and maybe the total print time.

Multiple moonraker instances on single machine

I have installed two printer instances using KIAUH. I would like to receive notifications from both printers using moonraker-telegram-bot. The instructions for this situation aren't clear to me.
Do I need to install two separate moonraker-telegram-bot instances as well? The only thing i find about multiple instances is the following:

[bot]
server: localhost

This is the adress, where the moonraker of the desired printer is located at.

In most cases it will be 'localhost'. Alternatively, an ip:port, as in 192.168.0.19:7125 can be entered,

if you are running multiple moonraker instances on the machine, or if the bot is located not on the printer itself

Can someone explain to me what I need to do, please?

ETA does not update

I was printing today with the bot in place and I noticed that the Finish at time does not update.
Mainsail ETA is lower than the bot reports.

Screenshot from 2022-01-05 15-57-01

Running the most simple config

[progress_notification]
percent: 100

Can't get a photo but video is working

Hello, I have the problem I can't get a photo sending the /photo command in bot chat. After the command I can see ">>>sending a photo" but then no photo is received. If I send /video the command is working fine.

Also all other commands are working fine, included macro, files and printer power on.

Any suggestion?

Thanks a lot

Не работает [timelapse]

Не работает [timelapse]
Пробовал абсолютно разные настройки ...
текущий конфиг

[timelapse]
basedir: /tmp/timelapse
copy_finished_timelapse_dir: /home/pi/timelapse/finished
cleanup: false
time: 5
target_fps: 15
manual_mode: false

p.s. файлы в папках не создает((

Originally posted by @DishersCave in #37 (comment)

Unfinished timelapses found

After requesting an image from telegram, its no longer possible to start the bot:

pi@raspberrypi:~/klipper_config $ Dec 21 16:50:45 raspberrypi systemd[1]: Stopping Starts Moonraker Telegram Bot on startup... Dec 21 16:50:45 raspberrypi systemd[1]: moonraker-telegram-bot.service: Main process exited, code=killed, status=15/TERM Dec 21 16:50:45 raspberrypi systemd[1]: moonraker-telegram-bot.service: Succeeded. Dec 21 16:50:45 raspberrypi systemd[1]: Stopped Starts Moonraker Telegram Bot on startup. Dec 21 16:50:45 raspberrypi systemd[1]: Started Starts Moonraker Telegram Bot on startup. Dec 21 16:50:48 raspberrypi python[5364]: 2021-12-21 16:50:48,035 - apscheduler.scheduler - INFO - Scheduler started Dec 21 16:50:48 raspberrypi python[5364]: 2021-12-21 16:50:48,170 - apscheduler.scheduler - INFO - Scheduler started Dec 21 16:50:48 raspberrypi python[5364]: 2021-12-21 16:50:48,472 - __main__ - ERROR - Uncaught exception Dec 21 16:50:48 raspberrypi python[5364]: Traceback (most recent call last): Dec 21 16:50:48 raspberrypi python[5364]: File "/home/pi/moonraker-telegram-bot/bot/main.py", line 847, in <module> Dec 21 16:50:48 raspberrypi python[5364]: greeting_message() Dec 21 16:50:48 raspberrypi python[5364]: File "/home/pi/moonraker-telegram-bot/bot/main.py", line 152, in greeting_message Dec 21 16:50:48 raspberrypi python[5364]: check_unfinished_lapses() Dec 21 16:50:48 raspberrypi python[5364]: File "/home/pi/moonraker-telegram-bot/bot/main.py", line 163, in check_unfinished_lapses Dec 21 16:50:48 raspberrypi python[5364]: bot_updater.bot.send_message(chatId, text='Unfinished timelapses found\nBuild unfinished timelapse?', reply_markup=reply_markup, disable_notification=notifier.silent_status) Dec 21 16:50:48 raspberrypi python[5364]: File "/home/pi/moonraker-telegram-bot-env/lib/python3.7/site-packages/telegram/bot.py", line 130, in decorator Dec 21 16:50:48 raspberrypi python[5364]: result = func(*args, **kwargs) Dec 21 16:50:48 raspberrypi python[5364]: File "/home/pi/moonraker-telegram-bot-env/lib/python3.7/site-packages/telegram/bot.py", line 521, in send_message Dec 21 16:50:48 raspberrypi python[5364]: api_kwargs=api_kwargs, Dec 21 16:50:48 raspberrypi python[5364]: File "/home/pi/moonraker-telegram-bot-env/lib/python3.7/site-packages/telegram/ext/extbot.py", line 207, in _message Dec 21 16:50:48 raspberrypi python[5364]: api_kwargs=api_kwargs, Dec 21 16:50:48 raspberrypi python[5364]: File "/home/pi/moonraker-telegram-bot-env/lib/python3.7/site-packages/telegram/bot.py", line 332, in _message Dec 21 16:50:48 raspberrypi python[5364]: result = self._post(endpoint, data, timeout=timeout, api_kwargs=api_kwargs) Dec 21 16:50:48 raspberrypi python[5364]: File "/home/pi/moonraker-telegram-bot-env/lib/python3.7/site-packages/telegram/bot.py", line 296, in _post Dec 21 16:50:48 raspberrypi python[5364]: f'{self.base_url}/{endpoint}', data=data, timeout=effective_timeout Dec 21 16:50:48 raspberrypi python[5364]: File "/home/pi/moonraker-telegram-bot-env/lib/python3.7/site-packages/telegram/utils/request.py", line 366, in post Dec 21 16:50:48 raspberrypi python[5364]: **urlopen_kwargs, Dec 21 16:50:48 raspberrypi python[5364]: File "/home/pi/moonraker-telegram-bot-env/lib/python3.7/site-packages/telegram/utils/request.py", line 279, in _request_wrapper Dec 21 16:50:48 raspberrypi python[5364]: raise BadRequest(message) Dec 21 16:50:48 raspberrypi python[5364]: telegram.error.BadRequest: Button_data_invalid

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.