OctoPi not reading SD card or print progress from Ender 3 (SOLVED)

What is the problem?
I just built a new Ender 3 I received earlier this month, it has come with the Marlin 1.1.6 firmware. I have not been able to take it apart to check the board model. In the web interface, the SD card does not display any files, and clicking the card icon gives only "Initialize SD Card" and no option to "Refresh SD Card". On the display on the Ender, instead of saying "Initialize" "Change" or "Print From" SD it now references TF instead.

I can manually print directly from the SD card by selecting print from TF Card on the printer. OctoPrint does show the file name and file size,, but none of the print progress displays.

Note that the temperature sensors are all working as expected.

The older Ender 3 was working properly in OctoPrint. I would have to power it back on to get it's full details.

What did you already try to solve it?
Restarted OctoPi, on printer manually issued "Change TF Card", restarted printer, rebooted OctoPi, ran commands from terminal to get Firmware version (M115), to Initialize the SD (M21), and to list files (M20) all ran successfully (see below)

Additional information about your setup (OctoPrint version, OctoPi version, printer, firmware, octoprint.log, serial.log or output on terminal tab, ...)

OctoPi built using balenaEtcher-Setup-1.5.24-x64 from Windows 10, and the image used was 2018-11-13-octopi-stretch-lite-0.16.0.img.

Recently ran update for OctoPrint to 1.3.11.

The Pi is Raspberry Pi 3 Model B Plus Rev 1.3.

Command output -
[...]
Send: M115
Recv: FIRMWARE_NAME:Marlin Creality 3D SOURCE_CODE_URL:https://github.com/MarlinFirmware/Marlin PROTOCOL_VERSION:1.0 MACHINE_TYPE:Ender-3 EXTRUDER_COUNT:1 UUID:cede2a2f-41a2-4748-9b12-c55c62f367ff
Recv: Cap:EEPROM:1
Recv: Cap:AUTOREPORT_TEMP:1
Recv: Cap:PROGRESS:0
Recv: Cap:PRINT_JOB:1
Recv: Cap:AUTOLEVEL:0
Recv: Cap:Z_PROBE:0
Recv: Cap:LEVELING_DATA:0
Recv: Cap:SOFTWARE_POWER:0
Recv: Cap:TOGGLE_LIGHTS:0
Recv: Cap:CASE_LIGHT_BRIGHTNESS:0
Recv: Cap:EMERGENCY_PARSER:0
Recv: ok
Send: M155 S2
Recv: ok
[...]
Send: M21
Recv: echo:TF card ok
Recv: ok
[...]
Send: M20
[...]
Recv: Begin file list
Recv: CE3_FD~1.GCO 92449361
Recv: 200~1.GCO 677213
Recv: 205~1.GCO 677213
Recv: End file list
Recv: ok

While a job is being printed, this is the output in the web interface for the current print job -
State: Operational
File: wall2-~1.gco (SD)
User: -
Timelapse: -
Approx. Total Print Time: -
Print Time: -
Print Time Left: -
Printed: - / 12.5MB

Forgot to add, that during the print, in the terminal the progress does display -

Send: M27
Recv: TF printing byte 429949/13056600
Recv: ok

Is the parser for the file reference and print progress looking for SD, and since that is now TF it is not recognized?

I will try to print from a file uploaded to the OctoPi directly when the current job finishes. (Wish I would have thought of that earlier)

Yes. There are protocol messages that OctoPrint relies on. If they suddenly get changed out of the blue, stuff will stop working as it should.

Hello. I stumbled upon this thread while googling exactly the same problem.
Octoprint 1.3.11 on Raspberry Pi 3, connected to Creality Ender 3 on stock firmware.
The connection works fine in terms of temperature monitoring and Terminal access, but Octoprint is never able to access SD Card that's inserted in Ender. "Initialize SD Card" button does not change anything, the terminal log is:

Send: M21
Recv: echo:TF card ok

Sending M20 manually returns a proper list of files on SD card:

Send: M20
Recv: Begin file list
Recv: CHAIN_~1.GCO 436498
Recv: CHAIN_~2.GCO 2850371
Recv: CHAIN_~3.GCO 1196389
Recv: CHAIN_~4.GCO 5224372
Recv: SCYTHE~4.GCO 746022
Recv: CE3_TO~1.GCO 1199654
Recv: 2BOARD~1.GCO 1805835
Recv: E3_CAM~1.GCO 949663
Recv: E3_COM~1.GCO 3753198
Recv: E3_HAN~1.GCO 2816271
Recv: SCYTHE~1.GCO 21462376
Recv: SCYTHE~2.GCO 13166081
Recv: SCYTHE~3.GCO 21786200
Recv: End file list

From reading this thread, it seems the culprit is the extra "echo:" in response to M21, which Octoprint does not parse as proper sd-card-ok message. I'd like to avoid flashing new firmware to the printer, it runs fine on the stock one.

So, if I'd like to change Octoprint's code to handle the M21 return with extra "echo:", do you have some pointers which files should I look into? Python is not my main programming language but I can work with it.

EDIT1: I can see that the M21 command gets sent from this place in the code:


but I'm not finding the code that parses the response, I'll be grateful for pointers.

No. The problem is that someone developing this firmware decided to change an established protocol message SD card ok into TF card ok without caring about the potential consequences of this.

The clean fix would be to revert the firmware back to referencing an SD card again (or better to scream at the firmware vendor to fix this mess). The clean workaround would be to write a plugin that turns these non conform messages back into conform messages on the fly.

As a novice plugin author, I took @foosel's response as a challenge and created:

# coding=utf-8
from __future__ import absolute_import

def convert_TF_SD(comm, line, *args, **kwargs):
    if "TF" not in line:
        return line
    goodline = line.replace("TF","SD")
    return goodline

__plugin_name__ = "Convert TF to SD"
__plugin_version__ = "1.0.0"
__plugin_description__ = "Convert TF to SD in printer responses"
__plugin_hooks__ = {
    "octoprint.comm.protocol.gcode.received": convert_TF_SD
}

which I named Convert_TF_SD.py and placed it in ~/.octoprint/plugins.

2019-05-29 13:28:57,259 - octoprint.plugin.core - INFO - 16 plugin(s) registered with the system:
|  Convert TF to SD (1.0.0) = /home/pi/.octoprint/plugins/convert_TF_SD.py

I don't have an Ender 3 so I can't test it and it may be too simple.

edit by @foosel See also this post further down for easy install instructions for OctoPrint 1.5.0+

6 Likes

Thanks, @b-morgan, I'll test your plugin.

@foosel as software developer myself I totally understand the frustration of having my software broken by changes in another piece of software, but as an end-user I have a duo of Ender and Octoprint that don't fully cooperate. And changing a line or two in non-critical web frontend sounds way more attractive to me than flashing my printer's firmware that could potentially brick it.

The plugin seems like a perfect middle-ground that keeps me (and other Ender3 owners) happy while not polluting Octoprint's core code.

1 Like

The problem is though, it doesn't stay at "a line or two". This week it's the newest Ender 3 firmware (btw, either this is a new firmware issue or no one so far tried to print from that thing's SD ever since it entered the market). Next week it's some other vendor breaking the temperature format. The week after it's some non conforming implementation of the busy protocol or a plain old misinterpretation of the wait response.

I've been doing this stuff for six years now and have been struggling with this stuff ever since the very beginning. A lot of this time I've tried running after breaking changes like the above that some vendor introduced and ending up with an unmaintainable mess of a communication layer that I now get to clean up and rewrite because it's just an absolute nightmare at this point.

The plugin system offers a possibility to implement workarounds for broken firmware for this very reason, so people like @b-morgan can jump in and safe the day :+1: Anything else is simply not sustainable.

I'm happy to help. I was inspired by other members of this community that have jumped in with a plugin solution for problems others have had.

IMO, some problems like this one don't need a full blown plugin in the repository. If we could collect (or tag) real world example plugins like this together somewhere that would be fantastic!

@b-morgan I tested your plugin and while it certainly loads (got the same plugin loading messages in octoprint.log) it does not help, the symptoms remain the same. Maybe it should also strip the echo: part? Or, since the logs in terminal are the same, maybe it's a matter of Python's string.replace returning a copy, so it should be something like:

    if "TF" not in line:
        return line
    goodline = line.replace("TF","SD")
    return goodline

I don't know Python (more of a Ruby guy) and I can't test it right now since I have to leave the office but will check both hypotheses in the morning (CEST timezone here).

Also, I think that an entire plugin for sanitizing specific printer's protocol breakage will be justified :wink:

@tomash I think your revision is correct. I'm a Python newbie so I should probably have invented something similar first so I could test it locally before unleashing it on the world!

When you get this to work, please post the final version (and I'll delete my post to eliminate any confusion).

The OctoPrint Docs are pretty good. The page @foosel linked above plus the Plugin Tutorial are what I used. There is a logger that can be used for debugging although I'm not exactly sure how to call it in this simple example. Perhaps someone will jump in with that part of the puzzle.

I can say that this is my second printer, and I received in just before going on vacation, so it was at home idle for a week until i put it together this weekend. The first printer, purchased as part of a different batch, was about 2 months ago, I'll have to power it back on to get the firmware on it, but I can tell just from the display it looked slightly different so I am sure it is a different firmware. I have two more to unpack and build from this last purchase. Love the low cost of the Ender 3! I will probably get one done tonight, and the other by the weekend. I also have to drop my order for some upgrade parts, the PTFE that comes with the Ender is not the best, and the original has a clog that I cannot clear. Can't believe I didn't order the tube when I bought them... ah well. I should be able to try and print from the Pi tonight as well, I am sure that will work fine. I just tend to want to print the bigger jobs from the SD, I heard somewhere that doing it from OctoPrint can have some odd results. Anyone able to verify or kill that rumor? It would be much more convenient to just use the Pi.

I think I would be more conservative on this...

def convert_TF_SD(comm, line, *args, **kwargs):
    if "TF card ok" not in line:
        return line
    line.replace("TF","SD")
    return line

I was going to do it that way but then I thought what happens if there's an error message that needs to be converted. I think @Tomash will end up being the guinea pig and figuring out whether to go conservative or go for broke :grin:

Also note the other bug he found:

    goodline = line.replace("TF","SD")
    return goodline

Confirming that after this small fix the plugin works as expected, I can finally see SD card contents in Octoprint and use Octoprint to order Ender to print from SD. :heart:

Thank you to everyone involved. @b-morgan , there are more people affected by this, should we publish this somewhere in Plugin Repository?

Also, @foosel , thank you for these six years of developing Octoprint, it's a great piece of software.

As a side note for reference, my Ender shows version 1.1.6 on about screen, if anyone wants to track this breakage.

1 Like

Yes, it should be published but I'm not sure about the plugin repository (because as is, it doesn't meet the requirements). I'm going to edit my original code snippet so that it is correct and I suggest that you edit the title so it contains "Ender 3" and mark my snippet as the solution.

I'm not the thread creator and I therefore can't edit the title. Not seeing any button "mark as solution" either.

Which requirements do we need to work on here in order to make a plugin that could be added to plugin repository? I'm reading Registering a new plugin and it seems we're OK here.

@Tomash My mistake, sorry. @Scott_Westberg is the one that needs to change the title and mark the solution.

In the Plugin Tutorial, Growing up, it says there are two ways to distribute your plugin but to the best of my knowledge, there are no "single file" plugins in the repository (@foosel please correct me if I am wrong).

There's a lot more work needed to convert this single file plugin into a plugin that meets the requirements for the "second way to distribute". In my ideal universe, there would be a second public repository for "single file plugins" like this one.

If you wish to pursue expanding this into a plugin repository submission, go ahead and do so. I don't feel comfortable doing that as without an Ender 3 of my own, I have no way to test it from beginning to end.

Hello,
I have the same issue I think. On my printer it doesn’t say print from sd, it’s TF. So is the octoprint not recognizing it due to it being TF. If so do I need to modify where “SD” resides to “TF” ? Thanks in advance.

Do you have an Ender 3? If not, what model printer do you have?

If so, read this post and follow the instructions.

1 Like