Can't connect to Moonraker after a power loss

Basic Information:

Printer Model: MANY
MCU / Printerboard: MANY
Host / SBC - Raspberry Pi Zero W
klippy.log - Attached

Describe your issue:

I have 7 machines running on dedicated RP Zero W’s.
I only install the bare minimum software for use.
I am currently using Raspberry Pi OS Lite (Bullseye)
Using KUAIH, I install Klipper, Mainsail, and Moonraker.
All machines work flawlessly until a power outage.
If I experience a power loss, I can no longer connect to SOME of the machines (Moonraker.)
This happens to random machines.
I can still ssh into the RP’s. (using the same wifi as Moonraker connection)
I have tried using KUAIH to uninstall and reinstall EVERYTHING.
No matter what I do I can’t reconnect to Moonraker.
I have tried using different browsers and different machines, but none can connect.
The only solution I have found is to reinstall the whole OS and start all over.
This is super annoying.
Can anyone determine what may be the cause?

Thanks, Mat


klippy.zip (813.3 KB)

After initial install and when finished configuration did you properly restarted them with a reboot command ?

This is my method:
Install OS using Raspberry Pi Imager.
install micro sd into Pi
ssh to Pi

################################################
I use the following “cheat sheet” I put together for efficiency:

sudo apt-get update
#Updates

sudo apt-get upgrade
#Upgrades

sudo reboot
#Reboot

sudo raspi-config
#Config Menu Advanced> Expand file system>choose to reboot.

sudo apt install git
#install GIT

git clone GitHub - dw-0/kiauh: Klipper Installation And Update Helper
#“kiauh address”

./kiauh/kiauh.sh
#Run KIAUH

Use KIAUH to install Klipper, Mainsail, and Moonraker.

ls /dev/serial/by-id/*
ls /dev/serial/by-path/*
#Check Device Serial> copy path into your “printer.cfg” file

~printer_data/comms/klippy.sock #Moonraker config file klippy.sock path (if needed)

Ok, but i don’t see a reboot after you did finish.

Why i’m pointing to reboot: very often OS Images uses journal filesystem, if journal is not properly stored (power outage) - system can rollback to some initial state (starting point of current journal).

When you do proper reboot after everything is done - journal will be properly saved and that point will be used next time as a starting point.

Okay, That sounds very logical. I will be trying that next. I just lost power to four machines, and only one can be connected to now.

I will redo it all with a reboot at the end. Hope that does the trick!

Thank you for your wisdom!

  • Mat

I reinstalled multiple machines.

I rebooted after installing everything.

I just unplugged my power, then plugged it back in while machines were idle.

I still can’t connect to some of the machines once powered back up!

Any other ideas?

login via ssh to machine which have issues and check that moonraker process is present with command

ps ax | grep moon

it should show something like this

749 ? Ssl 0:09 /home/debian/moonraker-env/bin/python /home/debian/moonraker/moonraker/moonraker.py -d /home/debian/printer_data
1234 pts/2 S+ 0:00 grep moon

next check moonraker service status with this command

systemctl status moonraker

it should display it’s status and few log lines

also you can check whole moonraker log file, usually it’s located in your home folder under printer_data/logs folder

cd ~/printer_data/logs
cat moonraker.log

if you can, download
moonraker.conf file from ~/printer_data/conf/moonraker.conf
moonraker.log file from ~/printer_data/logs/moonraker.log
klippy.log file from ~/printer_data/logs/klippy.log
and attach them to post

Here is the requested information:

Downloads.zip (82.5 KB)

Screenshot 2024-05-08 173009

Thank you for your time!

  • Mat

Ok, so from your logs i can say following things:
after restart your Moonraker is staring fine - no issues there
Klipper is also working properly and moonraker can see it

but i can see that your system did change it’s IP Address
for example if you search “Detected Local IP” in your moonraker.log file - you will see that in beginning it did have following address: 192.168.1.251 and eventually your Mainsail did connect to Moonraker from 192.168.1.4 address

but after reboot system did receive another address: 192.168.1.254
and no mainsail connections after that

So my conclusion is following: your system is changing IP address on reboot or power failure and Mainsail can no longer connect to it because it’s trying to use old IP Address

Why it’s happening and how to fix it:
When you configure your OS usually it should ask you what kind of network settings you prefer to use Static (Manually enter them) or Dynamic (DHCP- Automatic) network settings, if it’s not asking this, then by default it would chose to use Dynamic (DHCP) configuration because it will automatically give your system all require setting for accessing internet thru your router.

More about DHCP you can read here

When you do initial setup at some point your system will activate network and request network settings from DHCP and it will give those (including IP address) to your device and you are using then to setup Mainsail, but when your system is rebooting after power failure or commanded reboot - your moonraker system (with klipper) would again ask DHCP for network settings, but this time DHCP will give your system other IP address because of some internals reasons.

To fix this behavior it’s possible to re-configure your DHCP system to bind some specific IP address to exact device - this way DHCP will always give out same setting to specific device. For device it would look the same way - it did ask for setting and DHCP will give them, but they will always be the same. You can do that if you have admin access to your router, just read it’s manual and search there instruction how to bind IP address to MAC address in DHCP (MAC - is unique identifier of a network device). Usually it’s not hard, just few clicks.

If you don’t have access to your router then you can chose to use other approach - use Static network settings - for this you would need to define all required network settings in your moonraker instances manually, this way they will not ask DHCP for settings at all, because they already know them.

P.S. You always can switch already installed system to use Static or DHCP settings, you don’t need to re-install.

Hello,

I did have my router set to bind static IP’s to each of my Pi’s for OCD reasoning.
My router was binding static IP’s with mac addresses.

I removed the static IP binding in hope to resolve the connection issues after power loss. It didn’t help.

I think that your suggestion to set static IP’s through the Pi OS is the next step to try.

I will try figuring out how to get this done and report back!!

Thanks again!

  • Mat

Ok, as a quick workaround - you can add printer again in Mainsail, just use latest IP address with port 7126 - this port is defined in your moonraker.conf file

I can’t seem to be able to change the network to static IP in OS.
I am using a “lite” OS without GUI.
I tried a method from internet to change the connection using the terminal, but I get the error that “networkmanager” is not running.

Could you expand on the “workaround”.
Not sure how to “add” the machine back to mainsail…
Would I add the IP of the Pi to the “trusted clients” list??

To add in printer go to Mainsail settings

About networking - what connection type do you use ?
USB/Wireless ?

Wireless Networking connection

So, I always get the “You may have intended to navigate to one of Moonraker’s front ends, if so check that you entered the correct port in the address bar” screen when attempting to access mainsail via port 712X. I haven’t found an answer as to why.

When you supply that port - you actually connecting to moonraker port

Mainsail should be on the default port
for http address - it’s port 80
for https address - it’s port 443

Usually browsers are using default ports when you provide just name or IP address.

About static IP address
did you try to edit this file: /etc/dhcpcd.conf ?
usually it’s there and have comments about how to setup static IP.
You can edit it with this command

sudo editor /etc/dhcpcd.conf

I can’t access that page due to the OP issue.

Port 80 shows “connecting to printer.local” for a short time:

… then I get the moonraker error page:

Screenshot 2024-05-08 173009

I am able to pull files using Cyberduck.

Would I just “uncomment” some lines in the static IP section?

I have this:
dhcpcd.conf (1.7 KB)

Ok, so this means you did reach Mainsail - but it try to connect to moonraker and fail

Most probably you have single-printer setup which is configured in config.json file
refer to this and edit your config.json file