Webduino support for multiple file uploads

I’ve been working on bringing support for file uploads into the Particle branch of Webduino. This relies on the SdFat library along with Webduino modifications by Matthijs shared on this page.

https://code.google.com/archive/p/webduino/issues/10

I’ve got it compiling with the latest Particle branch of SdFat, and removed unnecessary library dependencies. It’s finally at a point where it can upload files brilliantly, but after any uploads the web server becomes unresponsive. The Photon does not crash, and you can even interact with web pages that are already loaded, but you cannot load another web page. They all timeout. Interestingly, if you enable WEBDUINO_SERIAL_DEBUGGING you can see that the page requests are processed and printed to the console, but just aren’t sent to the browser client anymore.

I’ve been spinning my wheels on this problem for a long time and I’m hoping someone can help out. I’ve boiled the problem down into a small project.

Here is a .ZIP of the project folder for Paticle Dev. Alternatively here are Gists of the sketch & modified Webduino sources.

You will need a Photon connected to an SD card (pins are commented in the source), and you’ll need to know your Photon’s ip address. Once you have those, upload the sketch, open a web browser and go to your Photon’s IP address. You’ll see a couple buttons at the top; one lets you toggle the blue LED on D7 and the other deletes all files in the root of your SD card (but not folders).

Below that you’ll see a form where you can upload files, and below that you’ll see some stats about your Photon and finally a list of files on the SD card. I recommend adding a folder or two to your SD so you can verify it’s being read when the file list appears (since the Delete button at the top doesn’t remove folders).

Try to upload some files to the SD card. Choose small files unless you want to wait, and you only need to upload one to make the problem appear.

Notice that the web server is unresponsive but you can still toggle the D7 LED, albeit with a ~1 second delay, as long as you have a second copy of the page open.

I would greatly appreciate any help on this. Perhaps @mdma would have some input since he ported Webduino to Photon. I don’t think the issue is related to SdFat, but perhaps @whg has some ninja ideas. Thank you!!

@Jerware

Thanks for your help on the web server for photon solution you shared. I realised over the weekend that the answers to my questions were in examples in the web server library. Authentication of users (login and logout). I had intended to move on to storing my webpages on SD card and reading them in when required rather than eating up program space.

File upload if definitely something I am interested in (for camera pictures) so I will follow and contribute where I can - although I think you are somewhat ahead of me. I noticed something today - firmware 0.4.9 is not compatible with the SD library for photon - when I switched to latest firmware my build spewed out a load of errors so I reverted to 0.4.7. Can I take it you are not using the web IDE version of the SD library and are you sure the SD part is working OK?

There was a problem with SPI that was reverted the same day 0.4.9 was released. You might want to try it again just to be sure. The library I used is SdFat, not the standard SD library. The standard SD library is actually based on an ancient version of SdFat, but SdFat has been developed substantially since then.

I’ve updated the project so no SD card or library is required. This sketch works with just the modified Webduino library pasted above. Instead of writing uploaded files to SD it prints the contents to the console (use small text files), but the same problem occurs after any upload. Hopefully this makes it easier for people to help troubleshoot!

I tried the program with no SD from uploadTest.ino · GitHub

I ran it on firmware-0.4.9-rc.3. I used the Chrome browser.

I get the "Upload Test" form. I select a small test file and hit the upload button.

the file content prints on the serial monitor and Chrome has a this message:

The Serial monitor has this:

Finished writing!
HTTP/1.0 200 OK
Server: Webduino/1.7
Access-Control-Allow-Origin: *
Content-Type: text/html; charset=utf-8

1file(s) uploaded.

Bytes: 662

SD Contents:

I hit the back arrow and the Serial monitor has this:

*** Connection timed out
HTTP/1.0 400 Bad Request
Server: Webduino/1.7
Content-Type: text/html

EPIC FAIL

Chrome has the Upload Test Form. I select a different file and it prints on the Serial monitor.

Finished writing!
HTTP/1.0 200 OK
Server: Webduino/1.7
Access-Control-Allow-Origin: *
Content-Type: text/html; charset=utf-8

1file(s) uploaded.

Bytes: 1494

SD Contents:

I can repeat this for other files and they are uploaded and print on the serial monitor.

The back arrow always produces this message.

*** Connection timed out
HTTP/1.0 400 Bad Request
Server: Webduino/1.7
Content-Type: text/html

EPIC FAIL

If I leave Chrome and try again, it fails and I must restart.

Sorry, I can't be of much help on WebServer.

Thanks, @whg. I believe you don’t have to leave Chrome for it to fail to load the page – you just have to refresh. Now that I think about it, it seems to continue handling POST requests, but not GET requests. You can send info to the web server, but it’s not sending anything back.

Anyone else have a chance to try this out? Again, the above project does not require an SD card. I’d appreciate input on whether the bug lies in the WebServer library or deeper in the TCPServer.

Alright, I got it working! I’ve updated the above code with the fixes. Hopefully someone finds it useful.

Hello Jerware,

Thank you for posting your upload test file. Is your updated implementation with SDFat still available?

-shm45

Yes, the gist above should still work.

Edit: sorry, I misunderstood. I’ll take a look at the sdfat code this weekend. Traveling now.