Issues using softAP for initial setup config

I made a first version of a setup web page based on the softAP example in the documentation. I simply added a

section with a small form above the wireless credentials to set a few parameters for my application (one time setup kind of stuff). After a few iterations of my application, i decided I needed to add a few more config parameters, so I split the config over three pages…one for some basic setup params (ip and port to post data to), a second page that has several radio button to enable/disable a few features, and a third page for the wifi credentials that would save the ssid/password and kick out of listen mode.

In doing this, I also wanted someone connecting again in listen mode AFTER an initial setup, to see the current settings correctly…so I created ‘index_html_template’ with some %d and %s to populate from EEPROM before sending the page back… however, my Photon did not like this once I moved to three separate pages (looking back, I;m surprised it worked when it was all one page)!!! Since myPages struct wants const char*, I dont think it liked me swapping out a char buffer that was filled in.

I tried changing “const char*” for the data element, and my photon goes to wifi disabled mode (white light). Change back to const char * and system will boot fine again…but some pages hang in “result->write” when (mostly the page that sets the wifi creds)…the ones that simply set the config params seem to work.

Can anyone shed light on what I could try…any reason why the html must be ‘const’?

The reason why const char* works and char* not is due to memory constraints.
If you make it const char* the data will be stored in flash memory, since it won’t/can’t be altered, but with char* it has to reside in RAM which is in short supply on these devices.
Hence transfering the data from flash to RAM will reduce the free memory for other tasks, consequently impairing their ability to work as intended.
If you want dynamic parts in your web page you can send the static page first, and then follow up with a JS script that injects the dynamic data into the page on the client side, or you split your page in sections (e.g. static part header and top section + dynamic part + static bottom section).

Thanks for the helpful explanation @ScruffR . Just to follow up on the issue/resolution, here is what I ended up doing that seemed to work quite well.

I did as you suggested and separated my pages into static and dynamic pages (changed ‘const char data’ in the myPages structure to 'const char staticPages’ and added a char *dynamicPages element - always one or the other is set to null). Dynamic pages are templates that I simply sprintf variables into before serving back to the browser. I tried using a data load, but didn’t like the delay I was seeing between page load and results showing up…full dynamic pages worked much smoother.

Unfortunately, I believe my main issue was that I simply used too much RAM in my code base (including, but not limited to, the web pages for the softAP/config screens). After removing one feature (which used large arrays of data), my config screens and the network/password screen works great!

Thanks for the quick response. You certainly gave me the push I needed to stick with this issue to a resolution.

1 Like