Photon SoftAP Outputs?

A while back @ScruffR did a really nice write up to add extra inputs to the softAP page, Photon SoftAP Inputs, however I am trying to change one of the outputs, namely for my purposes the device-id to our product serial number which consists of 6 hex digits.

My method described below is going to make some cringe, but it’s the only way I got it to work, I’m looking to learn a much more elegant way and one that uses less RAM space.

I have successfully done this by changing index_html from a const char to char, and this portion in index_html,
<input type=text id=‘device-id’ size=‘25’ value=’’ disabled
<input type=text id=‘mydevice-id’ size=‘25’ value=‘FFFFFF’ disabled

I then use strstr and strcpy to insert our serial number where “FFFFFF” is. Since mydevice-id doesnt exist the text field shows the default value which is our serial number.

Although it works, changing index_html from const char to char uses 1.2k of precious RAM.

Is there a way to accomplish this without having to change index_html to a char and still have a dynamic serial number?

Hope this makes sense and thanks in advance for your help,

You can split your page up into static and dynamic portions and instead of sending that page as one entity, you can do it in portions.

I’d have the dynamic part wrapped in a JS script that alters the value on the client side and gets injected between the </body> and the </html> tags.

Thank you @ScruffR but you can probably tell by the way I shoehorned the solution in that I have possibly less than zero experience with html and/or JS script.

Before responding though I did a quick google search about code injection and came up with several references to security risks. Probably not a concern though between a photon and a phone.or I’m not really knowing what I’m looking for when searching.

I hate to impose because I like to figure these things out for myself but I don’t even know where to start with this one so a short example would help, my serial number consists of 3 bytes.

I’d have to double check, but this would be the place I’d start

void myPage(const char* url, ResponseCallback* cb, void* cbArg, Reader* body, Writer* result, void* reserved)

This pushes the desired page to the client as is.
The simplest thing would be to split the desired page exactly at your device-id tag into two parts - one before the tag and one after the tag and in between you just insert the tag as you see fit.

  if (idx == yourPage) { // special treatment for the split page
    char tag[128];
    snprintf(tag, sizeof(tag), "<input type='text' id='mydevice-id' size='25' value='%06X' disabled />", yourID);

This way you wouldn’t need to bother with JS if you don’t want to :wink:

1 Like

Thanks @ScruffR, I’ll give it a shot and let you know how it pans out.

Thank you @ScruffR, it worked as advertised. The things I had to figure out for myself were what to put for “yourPage”, this was from the myPages array, the one I was trying to modify was the first one in the array so “0” was the correct choice. The second thing was a change to that array, in the first entry, which in my case is the page I’m trying to modify, replace index_html with “”, you do this because you’re compiling your page with the “special treatment for the split page” code. If you don’t do this you page will look like you,re presenting all or some of the elements twice. Finally I removed const char index_html, only needed the two halves now, const char partOne and const char partTwo.

Hope this helps someone else, for me it did what I wanted, taught me some new things, and best of all saved 1.2K of precious ram over my old method. :+1:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.