Fixing CanBUS BUS-OFF error with Klipper and a Voron
It's not a Klipper problem or a Voron problem. It's a Linux Networking Sucks problem. The Linux devs are constantly changing things so it is a moving target to set up networking making most documentation out on the internet wrong in a short amount of time.
I have my voron set up with a red emergency stop button. It kills the 120V power to the heated bed and the 24V power to the hotend, motors, chamber heater. I just felt better building it having an E stop... and honestly I use it to shut down the thing for the night so it only uses 5 watts for the Pi instead o the additional 35 watts the rest of the boards are using just sitting there as well as the lighting. Before I went to canbus this all worked perfectly until wires started to fail in the cable chain. So I upgraded to canbus. Problem is canbus does NOT recover cleanly from power loss. This is not a fault of canbus, its the fault of the idiots that wrote the linux software to manage networking. canbus can be in a "up" state but not be up and left in a BUS-OFF state. but the linux drivers see the network is up and does nothing.
So we need to fix it. and yes this is a dirty hack.
First write a script. I called mine canbus_restart.sh
#!/bin/bash
# Simple script to check and restart the can0 interface
# Check if the can0 interface is in BUS-OFF condition
# The output is piped to grep to check for the word 'BUS-OFF'.
if ip -s -d link show can0 | grep 'BUS-OFF' &>/dev/null; then
echo "can0 is down, attempting to restart it..."
# If can0 is down, bring it down and then up again.
sudo ip link set can0 down
sudo ip link set can0 up
fi
Make it executable and put it somewhere that you can find it.
The next part I am doing the easy way and not the overly convoluted mess that 90% of t he freaking internet wants you to follow. no we are not going to create service files and timer files for the service. Thats just stupid, and linux in general is running face first towards being extra stupid. we are going to go old school BOOMER style of running a script regularly and as root. Damned kids get off my lawn!
sudo crontab -e
Thats the command you issue. we are going to add TWO lines to crontab because I want to run the script every 30 seconds. Wait Cron cant do that! actually it can, and we are gonna do it the dirty ugly way that will have reddit wailing like banshees about it. add these two lines of code to the bottom of your crontab -e file.
* * * * * /home/tim/canbus_restart.sh
* * * * * ( sleep 30; /home/tim/canbus_restart.sh )
ERmaGherd! you know my username is tim! All the Russian hackers in the world will now P0wn me and make my printer burn the house down! Yeah no the internet makes people stupid they cant do shit with that.
Ok what the hell is going on with the crontab? the first line runs the script every minute. the second line runs it also every minute, but with a 30 second sleep. Meaning the scrip now runs every 30 seconds.
See us old fuckers are useful. Back in my day when we had to compile the linux kernel with a chisel and a bag of electrons we did things the simple way. Cron job and a script. Not all this overly convoluted service bullshit that seems to be shoved down everyone's throat today.
If this blog post feels extra spicy it is because I wasted several hours trying to solve this problem and it seems like 100% of all the klipper pages and forums don't have a clue how to fix it, reddit has no clue, nobody has looked for an answer. and of course the main source of info for setting up canbus for klipper has ZERO info about it. And from all my searching, I found a LOT of people have ran into this exact problem and everyone's answer is "you did something wrong" or "You sux lol"So now you have an actual answer to this problem.
Comments
Post a Comment