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

Files sent from Cura have the word "true" inside. #163

Open
Anyeos opened this issue Feb 12, 2021 · 11 comments
Open

Files sent from Cura have the word "true" inside. #163

Anyeos opened this issue Feb 12, 2021 · 11 comments

Comments

@Anyeos
Copy link

Anyeos commented Feb 12, 2021

When I send a file from the served webpage directly, it uploads correctly and have all the bytes inside (on the SDCard). But when I upload directly from Cura, the file size on the SD Card is only 4 bytes long and have the words "true" inside. So, all the file content is truncated with the word "true".
I think it is something related with Cura sending some command that WirelessPrinting missunderstands or maybe it is a bug.

@Anyeos
Copy link
Author

Anyeos commented Feb 12, 2021

I discovered that the problem is in:

  if (!index) {
    lcd("Receiving...");
    ...

Becasue Cura send index = 0 sometimes. So I will implement some other manner of checking to receive a file.

@Anyeos
Copy link
Author

Anyeos commented Feb 12, 2021

I just put a counter on the filename so I get filename+counter and I recevied 3 files, the last two with "true" inside. The first one is the real file.
So I need to implement some code to handle that correctly.
I guess that one of the "true" is the order to print. But to be sure I need to check Cura documentation.

@Anyeos
Copy link
Author

Anyeos commented Feb 12, 2021

Here a raw and rudimentary but working code for the purpose. Only modified the function "handleUpload".

int receivecount = 0;
String lastUploadedFullname;
void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {
  static FileWrapper file;

  if (!index) {
    // No quiero borrar los archivos, los quiero conservar
    //if (uploadedFullname != "")
      //storageFS.remove(uploadedFullname);     // Remove previous file
    int pos = filename.lastIndexOf("/");
    uploadedFullname = pos == -1 ? "/" + filename : filename.substring(pos);
    if (uploadedFullname.length() > storageFS.getMaxPathLength())
      uploadedFullname = "/cached.gco";   // TODO maybe a different solution

    if (lastUploadedFullname != uploadedFullname) {
      receivecount = 0;
    } else
    if (receivecount >= 3) {
      receivecount = 0;
    }

    receivecount++;
    if (receivecount <= 1) {
      file = storageFS.open(uploadedFullname, "w"); // create or truncate file
      lastUploadedFullname = uploadedFullname;
      lcd("Receiving: "+uploadedFullname);
    }
  }

  if (receivecount > 1)
    return;

  file.write(data, len);

  if (final) { // upload finished
    file.close();
    uploadedFileSize = index + len;
  }
  else
    uploadedFileSize = 0;
}

@probonopd
Copy link
Owner

Thank you @Anyeos. Do you think you could send a pull request?

@Anyeos
Copy link
Author

Anyeos commented Feb 12, 2021

Thank you @Anyeos. Do you think you could send a pull request?

I need to improve the code if not you will need to upload 3 times from the web to bypass the counter (that is some workaround for Cura). For now it is working as expected with Cura 4.8 only. I will improve it eventually but not today.
For now you can copy / paste the above code.

@probonopd
Copy link
Owner

Does this also continue to work with PrusaSlicer @Anyeos?

@Anyeos
Copy link
Author

Anyeos commented May 6, 2022

Hello, all is working good for now with Cura, PrusaSlicer, etc. I improved the code a lot so it is working better. Can cancel, send file, print, cancel, print... it works good.
It does not mean it is perfect but I am using it periodically without issues.

The code is published on a fork that I made. If you have the time to study the code feel free to do so. I am very busy and cannot do a pull request or a patch.
Or you can use my fork because that is what I am using.

I implemented the network serial interface too so you can control your printer directly from a network as if connected directly to USB on computer. Ie.: you can use it on MatterControl too.

@probonopd
Copy link
Owner

That sounds interesting @Anyeos. Thanks for letting me know.

@Anyeos
Copy link
Author

Anyeos commented Nov 23, 2024

Hello friend, I come here because I want to leave a link to my fork because nobody knows about it but I did a heavy job already. It is a waste if nobody knows or try it. But I found this chat so I will put it here.
I give you the proper thanks at bottom because you motivated me doing this and because I still used some lines of your code. But I wrote it from scratch.
It uses async web and a own wifi manager. You can use that in your own proyects because it is separated.

Here the fork: https://github.com/Anyeos/NeoWirelessPrinting

Update: I did some changes some days ago but I didnt uploaded it yet. So expect some changes published in a near future.

@probonopd
Copy link
Owner

Hello @Anyeos, thanks for your work. How about sending pull requests so that your improvements can be upstreamed?

@Anyeos
Copy link
Author

Anyeos commented Dec 2, 2024

Hello @Anyeos, thanks for your work. How about sending pull requests so that your improvements can be upstreamed?

Because it is a lot of code and there are no relation on filenames and on code structure. I developed a completely new approach starting from the web server that is asynchronous non blocking. The "Wifi manager" that I implemented does not exists, nobody created it, it is my own creation. The approach is using a minimal filesystem to serve the web files. My project have a complete web UI full async.
In fact you can use all my async web and wifi manager in any project because it is a complete separate C class and directory structure ready for copy paste on other projects.

So... to pull some code I need to write the code on your own files at first. 🤷

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