Open Anyeos opened 3 years ago
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.
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.
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;
}
Thank you @Anyeos. Do you think you could send a pull request?
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.
Does this also continue to work with PrusaSlicer @Anyeos?
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.
That sounds interesting @Anyeos. Thanks for letting me know.
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.