Photon softAP usage?

The photon doesn’t really care about the content type, so feel free to set it to text/plain.

@mdma, Thanks for the info.

@mebrunet, I used the example from your GitHub repo and was able to get it working with just a minor change in the content type, “text/plain” vs “text”.I was also able to render the page from a remote server, toggle my wifi to connect to the Photon’s AP, and configure the WIFI on the Photon via HTTP. That being said, I don’t believe there is an issue with CORS.

1 Like

@juststan - I did the same thing this weekend! So looking like OPTIONS is unnecessary. Out of curiosity, what firmware version were you running?

@mebrunet 0.4.4.

Everything is working on v0.4.4 and develop. The page can now be served from the Photon and/or an external host. i.e. CORS issues have been resolved.

@juststan - While Content-Type: text/plain on the POSTs avoided the preflight OPTIONS, the Photon started returning 404s. Instead setting Content-Type: multipart/form-data worked for me. Strange that you didn’t get the same error… are you sure the text/plain headers were being applied?

@mdma - Pull request against develop here.

1 Like

This is awesome! Great work!

I have one question - can someone speak to the flow and structure of the CORS-type setup? I don’t quite see the big picture here:

  1. Where does the web source go,
  2. When and where does the user connect to the Photon?

I’m guessing you just take the web source from the endpoints defined in this PR, serves it remotely, then the user toggles to the Photon’s AP and uses the buttons? Not sure if I have that right though.

Yeah, content type was set properly. The browser would have gone down the options route othersise.

Ya, fair enough. Well that’s just weird then. Not sure what was happening on my end.

@msolters

When using this in a CORS-type setup (i.e. hosted somewhere other than the Photon being connected), the pull request isn’t of much interest to you. Instead, as you suggested, you’d want to serve the src folder of this repo, and make sure you’re running v0.4.4 of the firmware on the Photon in question (or building firmware right from develop). The person wishing to connect the Photon would then:

1- Visit the url where you serve the src content with a modern browser. This would load all the necessary scripts/resources.
2- Put the Photon in question into listening mode.
3- Disconnect their existing WiFi connection and connect to the Photon’s AP.
4- Follow the steps on the page they loaded in step 1 (clicking various buttons on the page to scan available APs & connect… etc) .
5- Reconnect to the previous WiFi (this will likely happen on it’s own when the Photon’s AP disappears).

However, the code was written to take the user through the case when the src folder is actually being served by the Photon, so the instructions don’t quite match and would need tweaking. In that case the connection procedure is ordered 2,3,1,4,5. Since the “url” is 192.168.0.1 (or whatever else you’ve set it to) on the Photon’s network.

Honestly, I imagine people taking the CORS approach will probably re-write their own connection page from scratch (…though the RSA tools I compiled are useful). The problem solved in the repo above isn’t “how to make a great SoftAP page”, it is “how to make a barebones SoftAP page that can be compressed and embedded into the Photon’s core firmware”. Hence the pull request.

I hope that clears things up!

@mebrunet Totally! Thanks for the detail.

I only ask because I’ve already implemented a basic reactive framework using Meteor.js that does just this (i.e. 2,3,1,4,5), by using a Browserified branch of softap-setup-js by @brewnerd. I was curious what might be different and hopefully advantageous in your CORS approach. Based on the information above it seems to be six of one half a dozen of the other.

I very much like having the setup embedded right into the Photon, though!

Please tell me that a hosted page like this will make its way into the main photon branch @mdma ? This has been the one thing needed to make the photon platform very versatile and useful in an iOT project. No apps to download, accounts to create, just a simple way to get the device online. Love it @mebrunet !

4 Likes

I agree - it’s a great contribution! We’re discussing this internally in the team and weighing it up with our planned solution of having the webapp hosted outside the device. We’ll post back once a decision is made.

4 Likes

Just FYI: Content-Type: text/plain didn’t fix the CORS issue for me… Content-Type: multipart/form-data did work, as @mebrunet pointed out.

I’m developing in Sencha Touch in Firefox.

is this now part of the 0.4.4 firmware or do I have to build and flash the firmware here?

Great work thanks for the effort!!

getting an error while compiling @mebrunet 's firmware. This is my 1st time to compile a Particle firmware.

I downloaded the firmware from the website not from Git. I go into the modules folder and I am getting the following error

C:\Photon\modules>make clean all PLATFORM=photon -s program-dfu
"C:/Photon Programs/Git/bin/sh.exe": line 1: stat: command not found
head: -38: invalid number of bytes
make[1]: *** […/…/…/build/target/system-part1/platform-6-m-lto/system-part1.bin] Error 1
make: *** [C:/Photon/modules/photon/system-part1/makefile] Error 2

I have added all the paths to the environment variable, I confirmed that they are working and also confirmed the C:/Photon Programs/Git/bin/sh.exe is there.

What am i missing?

Thank you for your help

@mrabie

A couple questions to help you.

  1. When you say:

I downloaded the firmware from the website not from Git

What website do you mean? Please link to the download.

  1. Were you able to build the "vanilla" v0.4.4 or develop versions of the firmware? i.e. those version before they were modified to serve a SoftAP page? If not, I'd recommend doing that first. Also if you have questions about how to do that I'd recommend asking them on a different thread for clarity. (Feel free to tag me nonetheless).

The error is mentioned here:

See:

1 Like

Thank you for the replies and help.
@kennethlimcp it worked following your tutorial.
@mebrunet I wasn’t clear I downloaded the firmware here. Now I am able to build and flash the firmware(s).

There’s a problem with Safari on iPhone. When pointing the Safari browser to 192.168.0.1/ it keeps loading and then comes back with can’t open page error. Tried it on Chrome on iPhone it works perfectly.

Thank you

Does flashing my my WebIDE firmware breaks the functionality?

  1. Setup my Photon WiFi through SoftAP page
  2. Wrote my app on WebIDE
  3. Flashed my app to the Photon
  4. Put Photon in Listening Mode
  5. Connected to Photon WiFi
  6. Tried opening the SoftAP page again, now I am getting page can’t be loaded.

My understanding is that the WiFi setup doesn’t get wiped when I flash my custom app. Sorry for my confusion.

Thank you for your help

That download is out of date as is builds the SoftAP page with v0.4.3. It is preferable that you download from here (Download Zip link lower right) which builds it with develop.

@anthonywebb has also noticed the code not working with Safari. See bug here. We’re not sure why yet…