SoftAP: Loading webpage from memory

I’m using the SoftAP to host webpage and display things to the user.

cb(cbArg, 0, 200, myPages[idx].mime_type, nullptr);
result->write(myPages[idx].data);

I would like to be able to load webpage directly from an SD card instead of having to store everything in big buffers like the SoftAP example does.

How should I do that?
I’m not sure what is the best way to pass the data to the Writer.

I could load temporary the page in ram (with malloc) and pass it to the writer and then flush it but there must be a better of doing this.

Suggestions? Thanks!

Any ideas?

If you’re intending to use the SDFAT library for your project, you could ping @whg if he could suggest a way to hook your writer up with the SPI DMA access he’s using in his library.

That way you could keep your buffer (which I wouldn’t necessarily allocate on the heap) as small as possible.

I would like to try with an SD card but I’m actually also using SPI flash with SPIFFS and I would like this to work for both systems.

I’m little bit lost because it’s a stream. Is there a way to continue to add data to it?

Thanks

StreamClass is a base/ancestor class used for all kinds of classes e.g. Serial, Serial1, HTTPClient, …
This doesn’t mean you’d need to provide an uninterrupted stream of bits comming to have it work properly (see Serial.print()).
Granted, there are timeouts for some of them, but a few milliseconds usually don’t matter - most (if not all) of them are asynchronous streams where timing is not a big issue.

Thanks, I just realised that in fact it’s quite simple…

I simply have to do multiple result->write in a loop and the string class should handle it… I’ll try an see if there is any problem with big files.

@Suprazz Will this webpage just have data or will it update certain data live from the sensor inputs?

It sounds interesting; I ended up using SD card in my project instead of SPIFFS, so if you get this working with SD cards let me know.

Also, I would like to see what the webpage looks like once you have it completed if you can share. It just gives me a better idea of what all is possible with the Photon’s WiFi

Hi,
No live data yet but a full configuration of my product using json and Post with javascript

2 Likes