Automatic restart if MCU is detected

Since I turn off my printer once in a while and keep the RPi running it would be convenient to detect the MCU connection via USB and trigger an firmware-restart. I searched with the klipper context and found the following USB rule that I adapted to look for my MCU: in /etc/udev/rules.d/98-klipper.rules I use: SUBSYSTEM=="usb", ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="614e", ACTION=="add", RUN+="/bin/sh -c '/bin/echo FIRMWARE-RESTART > /tmp/printer'" the ACTION part will obviously not work with RatOS - is it just a different path to the "printer"? Or is it a completely different command that triggers a firmware restart? Thanks!
6 Replies
miklschmidt
miklschmidt•8mo ago
Why wouldn't it work? Did you try? RatOS currently does something similar, it logs "MCU Detected" to /var/log/ratos.log when a board is connected, via the klipper-mcu-added.sh script. If you don't mind moonraker complaining about a dirty repository you could add echo FIRMWARE_RESTART >> /tmp/printer to the end of that script.
beejayf
beejayf•8mo ago
@miklschmidt - yes I did - the printer did not connect - instead I found a file named "printer" containing "FIRMWARE-RESTART" in /temp :-!
miklschmidt
miklschmidt•8mo ago
Yeah you're script was wrong (i wrote the corrected one in my last comment) oh there is no /tmp/printer anymore, interesting Well, you can call moonraker instead curl -X POST http://localhost:7125/printer/firmware_restart will call FIRMWARE_RESTART through moonraker so it would be
SUBSYSTEM=="usb", ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="614e", ACTION=="add", RUN+="/bin/sh -c 'curl -X POST http://localhost:7125/printer/firmware_restart'"
SUBSYSTEM=="usb", ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="614e", ACTION=="add", RUN+="/bin/sh -c 'curl -X POST http://localhost:7125/printer/firmware_restart'"
beejayf
beejayf•8mo ago
Hmm - thanks a lot! This triggers a restart but as long as I keep the rule in the mcu will not reconnect. Somehow the rule created a loop as it appears to trigger again in the connection process. I will look into the linux part and try to find a rule that will trigger on the mcu being powered on but not on the connection part.
miklschmidt
miklschmidt•8mo ago
Ah it might overrule the other rule. FIRMWARE_RESTART will trigger a reconnect on the MCU So.. 😂 Didn't think of that, lol Maybe a simple restart is enough for what you need? so http://localhost:7125/printer/restart instead
beejayf
beejayf•8mo ago
I forgot to write that I tried both - all leads to a loop I thought to write a little script that will only send the restart command if the last restart is more than 30 seconds old - but then again - that might be overly complicated for just convenience and a manual click of restart is acceptable...
Want results from more Discord servers?
Add your server