klipper icon indicating copy to clipboard operation
klipper copied to clipboard

Support busy protocol

Open darko371 opened this issue 8 years ago • 9 comments

We now official support Klipper since repetier-server version 0.90.0 and it works great with latest patch. However there is a problem with timeouts. Hosts normally have a timeout so they can reset failed communication e.g. a lost "ok". Also klipper with the server internal connection is unlikely to have that issue is still handled by the serial connect method, so it has a timeout to reset communication. See this log for example:

20:05:59.322: #bed_tilt_calibrate
20:06:12.139: // probe at 52.000,103.000 is z=1.795000
20:06:16.619: // probe at -25.000,25.000 is z=1.917500
20:06:20.427: // probe at 52.000,25.000 is z=1.867500
20:06:24.266: // probe at 130.000,25.000 is z=1.780000
20:06:28.122: // probe at 130.000,103.000 is z=1.732500
20:06:31.864: // probe at 130.000,175.000 is z=1.677500
20:06:35.738: // probe at 52.000,175.000 is z=1.717500
20:06:39.320: Warning: Communication timeout - resetting communication buffer.
20:06:39.320: Connection status: Buffered:123, Manual Commands: 1, Job Commands: 0
20:06:39.320: Buffer used:123 Enforced free byte:13 lines stored:9
20:06:39.586: // probe at -25.000,175.000 is z=1.652500
20:06:43.348: // probe at -25.000,103.000 is z=1.790000
20:06:43.735: // stepper_z position_endstop: 1.557416 (when Z homing at 52.000,103.000)
20:06:43.735: // x_adjust: -0.000367 y_adjust: -0.001149
20:06:43.735: // The above parameters have been applied to the current
20:06:43.735: // session. Update the printer config file with the above to
20:06:43.735: // use these settings in future sessions.

One solution is that users set timeout very high, but even if I write it somehwere they are likely to not read it. There is a official solution already supported by Repetier-Firmware and Marlin und hence understood by several hosts. It is sending

busy: reason

or Marlin like as

echo: busy: reason

every x seconds, normally every 2 seconds if firmware is blocking for longer then 2 seconds. This resets the timeout timer in host. So as long as this gets send every 2 seconds for slow commands hosts will not assume it is communication problem. The nice thing is that it works for all gcodes even if host do not know that a command is slow (especially here, where it is no gcode at all). Every "ok" on your side can reset your internal timer. If no commands are present you do not send busy of course. reason can be any string. Typical things are heating or processing. Important is to have no exceptions. If you support busy the timeout of 3 seconds on server side should not cause a timeout that way.

The # before the command tells the server to send the command 1:1 and not interpret it as gcode.

What do you think? I think this is the only solution mor ehosts support it. Otherwise I would need a special Klipper handling disabling timeout for that firmware. Would then be a server only solution that others would need to copy/implement as well. How sure is it that there will be no com errors between klipper and server? Not that I have seen one so far.

darko371 avatar Jul 09 '18 07:07 darko371

On Mon, Jul 09, 2018 at 12:27:18AM -0700, repetier wrote:

We now official support Klipper since repetier-server version 0.90.0 and it works great with latest patch.

Great!

However there is a problem with timeouts. Hosts normally have a timeout so they can reset failed communication e.g. a lost "ok". Also klipper with the server internal connection is unlikely to have that issue is still handled by the serial connect method, so it has a timeout to reset communication. See this log for example:

20:05:59.322: #bed_tilt_calibrate
20:06:12.139: // probe at 52.000,103.000 is z=1.795000
20:06:16.619: // probe at -25.000,25.000 is z=1.917500
20:06:20.427: // probe at 52.000,25.000 is z=1.867500

Why not reset the timeout on any valid input that is received from the printer? This is what (it appears) OctoPrint does.

How sure is it that there will be no com errors between klipper and server? Not that I have seen one so far.

A pseudo-tty won't drop or corrupt data.

-Kevin

KevinOConnor avatar Jul 09 '18 17:07 KevinOConnor

Why not reset the timeout on any valid input that is received from the printer? This is what (it appears) OctoPrint does.

Bad idea in general. Marlin/Repetier for example support autoreport temperature. So we get a response every second, but that does not say anything about the commands being executed or waiting for next command. Only a "ok" says that command buffer is free for next and with com errors it is possible to miss one and that is what the timeout is for.

So since you say you will not drop any line and always repspond with a proper ok I will just disable timeout for Klipper in the next update and hope it causes no problem we currently do not see.

darko371 avatar Jul 10 '18 06:07 darko371

I have actually made a simple keepalive module for Klipper. I'm using it with Repetier-Server. It's still in my local repo but you can specify the interval in seconds and when Klipper is printing and busy processing gcode then it will output busy: processing after an interval.

mcmatrix avatar Sep 17 '18 07:09 mcmatrix

Is this issue related to the fact that Klipper stops reporting temperature to Octoprint during BED_TILT_CALIBRATE? I'm experiencing that, but don't want to rush for the new issue button.

mamoit avatar Nov 09 '18 14:11 mamoit

The classic way to get temperatures is sending M105 from time to time. During a long command hosts can not send new commands and will not get new temperatures unless firmware does this on it's own, e.g. because it has autoreport temperature feature so no M105 is required or it reports temperatures on it's own like done normally during M109. I have no klipper printer so can not say what klipper supports here, but I guess it requires the M105 method so it will pause updating temperatures during these commands.

darko371 avatar Nov 09 '18 15:11 darko371

It appears that a work around has been found for this and it appears it is not necessary for Klipper to support the "gcode busy protocol". As such, I'm going to close this issue.

Thanks, -Kevin

KevinOConnor avatar Feb 25 '19 16:02 KevinOConnor

Where can I find this workaround?

mamoit avatar Feb 25 '19 22:02 mamoit

Upgrade Repetier-Server and select Klipper firmware. Timeout is there disabled to solve it.

darko371 avatar Feb 26 '19 07:02 darko371

I found this issue specifically because I am struggling with Octoprint killing a long-running command because there's no busy signal. Is is possible to reconsider this issue @KevinOConnor?

itsthejoker avatar Dec 17 '20 00:12 itsthejoker