Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate temperature reporting in Octoprint #3

Closed
Sebazzz opened this issue Sep 26, 2020 · 8 comments
Closed

Fix duplicate temperature reporting in Octoprint #3

Sebazzz opened this issue Sep 26, 2020 · 8 comments

Comments

@Sebazzz
Copy link
Collaborator

Sebazzz commented Sep 26, 2020

The duplicate temperature reporting issue is still present on this firmware. We need to fix it.

I got contacted by an individual (to protect his privacy - but still give him credit, I'Il call him RC):

You notice that in Octoprint, sometimes the temperature comes out correct but mostly during a print it comes out wrong. If you issue a M150 command it comes out right. It is only when M155 (auto report) is set that it comes out wrong. Octoprint automatically turns on auto report (see settings->serial connection-intervals & timeouts). You’ll notice that autoreport temperature interval is set to 2s. This is the value used in a M155 command. If set to zero it turns off autoreport and polling automatically begins which uses the M150 command. The temperature comes out correctly when polling. Armed with this information I went digging around in the M150, M155 command code and temperature.cpp code where the temperature is reported. I was looking for a place where it sent the characters twice. The SERIAL_OUT macro defined in serial.h below seemed to be the obvious culprit.

   #define SERIAL_OUT(WHAT, V...) do{ \
      if (!serial_port_index || serial_port_index == SERIAL_BOTH) (void)MYSERIAL0.WHAT(V); \
     if ( serial_port_index) (void)MYSERIAL0.WHAT(V); \
   }while(0)

As you observed, Creality changed MYSERIAL1 to MYSERIAL0. If serial_port_index is set to SERIAL_BOTH the characters (and number strings) will be doubled since both if’s will be true. It just so happens that the only place SERIAL_BOTH is used is in a PORT_REDIRECT in the autoreport code in temperature.cpp (Marlin/src/module) around line 2924 in the file from Creality. What I don’t understand is “where does serial_port_index get changed back after using PORT_REDIRECT”. I’ll have to look at that some more.

   void Temperature::auto_report_temperatures() {
     if (auto_report_temp_interval && ELAPSED(millis(), next_temp_report_ms)) {
       next_temp_report_ms = millis() + 1000UL * auto_report_temp_interval;
       PORT_REDIRECT(SERIAL_BOTH);
       print_heater_states(active_extruder);
       SERIAL_EOL();
     }
   }

“serial_port_index” is typically “1” therefore the second line outputting to MYSERIAL0 is used. It is only when set to SERIAL_BOTH that the characters get output twice. My initial thought was to put MYSERIAL1 back in serial.h and swap the port numbers for SERIAL_PORT and SERIAL_PORT_2. But after looking some more I’m not sure what other side affects this may have. I know this is what is causing the problem, I just don’t know what other things Creality may have done that could be impacted. I hope this gives you something to look at and I’ll look at it again tomorrow to see what has to be done to unravel Creality’s change. I would like to get back as close to Marlin code as possible.

@Sebazzz
Copy link
Collaborator Author

Sebazzz commented Sep 26, 2020

I think Creality changed the macro because serial port 1 MYSERIAL1 is used for communicating with the touch screen:

https://github.com/Sebazzz/Marlin/blob/f3876e81a74b8ffebdef7776e721f7c25e0ce770/Marlin/src/lcd/dwin/LCD_RTS.cpp#L477-L478

https://github.com/Sebazzz/Marlin/blob/f3876e81a74b8ffebdef7776e721f7c25e0ce770/Marlin/src/lcd/dwin/LCD_RTS.cpp#L345-L348

Perhaps we should not let Marlin know about this serial port and initialize it manually.

@NickDevoctomy
Copy link

FYI, not sure if this adds anything or not, but there are plugins available for OctoPrint that fix the issue of it not reporting correctly,

image

Unless this is a different issue of course.

@Sebazzz
Copy link
Collaborator Author

Sebazzz commented Sep 26, 2020 via email

@NickDevoctomy
Copy link

Sure, I was providing an immediate workaround.

@Sebazzz
Copy link
Collaborator Author

Sebazzz commented Sep 26, 2020

I suppose we could just try and revert that macro altogether. I’ve been analyzing the source code for Bugfix-2.0 in combination with the Configuration.h files for the Ender 3 V2 and everything checks out.
The Ender 3 V2 also uses MYSERIAL1 to talk to the touch screen so I think we can simply revert the change in the macro.

@Sebazzz
Copy link
Collaborator Author

Sebazzz commented Sep 26, 2020

Reverted the Creality change in 71ed695. Currently testing.

@Sebazzz
Copy link
Collaborator Author

Sebazzz commented Sep 26, 2020

Fixed in 71ed695

@Sebazzz Sebazzz closed this as completed Sep 26, 2020
@Sebazzz
Copy link
Collaborator Author

Sebazzz commented Sep 26, 2020

For those who wonder why this works, it appears the touch screen ignores messages it can't handle:

image

Sebazzz pushed a commit that referenced this issue Mar 7, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Update platformio scripts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants