Using photonsoftap.meteor.com, the process still seems to get jammed at the configure-ap
step, but this time without any response from the server at all. It looks like the issue may be that the underlying softap-js library uses an HTTP OPTIONS request rather than a POST, because when I modify the python test script to use OPTIONS, I never see a response come back:
I can confirm that this is working in my React Native application on an iPad running the latest iOS! Iām definitely doing a POST using a JS call to fetch
.
For photonsoftap.meteor.com, itās really puzzling where the OPTIONS request is even coming from, since the softap-setup-js package uses a POST as well:
https://github.com/spark/softap-setup-js/blob/master/softap.js#L242
Great news re: the PR, @mdma! Iāll try to pick this JS thread back up tomorrow and see where I can get.
@indraastra ā One thing to keep in mind is that the browser is not actually going to run softap.js
. Itās going to run the browserified transformation of that file, and that transformation is going to load different HTTP handling libs, and different methods, all of which depend on the browser it happens to be running on. The real litmus test is to debug (a) the manually browserified resource, or (b) the transformed resource generated by cosmos:browersify
, in the Meteor example.
I have a few forks of the SoftAP software where I try different libs to begin with, which produce different substitutions, and different request types as a result. For reference:
var opts = {
method: 'GET',
url: 'http://' + this.host + '/' + cmd.name,
withCredentials: false
};
if((cmd.body) && typeof cmd.body === 'object') {
opts.json = cmd.body;
opts.headers = { 'Content-Type': 'multipart/form-data', 'Accept': '*/*'};
opts.method = 'POST';
}
xhr( opts, function(err, resp, body) {
if (err) {
throw new Error(err);
}
data(body);
} );
Iāll post more tomorrow if I get around to it.
Ok, after some hair-pulling, I tracked it down to a workaround that was mentioned multiple times above - that of needing to lie about the content type. Setting the type to āapplication/x-www-form-urlencodedā does the trick:
https://github.com/spark/softap-setup-js/blob/master/softap.js#L241
You can actually just replace the Content-length
field like so:
opts.headers = { 'Content-type': 'application/x-www-form-urlencoded' };
For some mysterious reason, this changes the request into a POST and allows it to successfully complete. I donāt know if this is going to break any other clients, thoughā¦
@msolters - Thanks! The sheer number of layers involved to get all this to work is still a bit stupefying. I would have expected the http
module to be provided by http-browserify
, but looking at ./.meteor/local/build/programs/web.browser/app/client/softap.browserify.js
, it looks like the whole http library has been lifted straight out of Node? Is browserification of modules not transitive, or does it somehow realize that the builtin module is browserify-friendly?
Edit: Also, please see my post just below yours. It looks like some kind of form-related content type is required for the request to be made as a POST.
Itās true that, for the most part http
should map to http-browserify
. Thatās assuming weāre using HTTP, and the kicker is that the *-browserify
modules typically have a bunch of shims and work-arounds for all the weird edge cases. For example, what if we are using typed blobs as message content? What if we canāt use blobs? What kind of arrays can we use? Thereās a million and half little differences that will manifest in the browserified modules.
In same cases, modules may fall back to other modules entirely. If you really dig through that browserified source youāll see what I mean. (Check out the crypto- and random number methods!) I think the best path to getting something working is going to be replacing the HTTP lib with something whose browserified substitution has as few such incompatibilities and therefore as few hacks as possible. Thatās why I made a version that depends on XHR instead.
The upshot here is that with the multi-packet workaround, these header-bugs (which we were so eager to blame in the beginning) are at last actually the problem at hand! Which means we ought to be able to JavaScript our way out of this one.
This may have been alluded to earlier, but here are some juicy quotes from the HTTP CORS docs to shed some light on the OPTIONS mystery:
Unlike simple requests (discussed above), "preflighted" requests first send an HTTP request by the OPTIONS method to the resource on the other domain, in order to determine whether the actual request is safe to send. Cross-site requests are preflighted like this since they may have implications to user data. In particular, a request is preflighted if:
It uses methods other than GET, HEAD or POST.
Also, if POST is used to send request data with a Content-Type other than application/x-www-form-urlencoded, multipart/form-data, or text/plain, e.g. if the POST request sends an XML payload to the server using application/xml or text/xml, then the request is preflighted.
So using any of application/x-www-form-urlencoded
, multipart/form-data
or text/plain
would have prevented an unnecessary OPTIONS request that the server never acknowledges.
Or that blocks the the subsequent packet! This explains why I was able to get SoftAP working on Safari on El Capitan when I used the XHR version with multipart/form-data
, but not otherwise.
So if we can get this (perhaps text/plain
would be less of a kludge) into softap-setup-js with some more testing, it would be enough to fix the issues with the meteor app as well, right?
@indraastra Here, download this and include it directly into whatever youāre working on. Itās the browserified SoftAPSetup but Iāve set the Content-Type as you requested.
The source is here:
I donāt have any Photons in front of me right now
Is the addition of the content-type header the only change in this file? If so, thatās pretty much what I tested already and confirmed working by modifying ./.meteor/local/build/programs/web.browser/app/client/softap.browserify.js
when running the meteor app locally. Sorry if I wasnāt super clear about it earlier.
In other words, it looks like adding that as the content type makes the photonsoftap app work for me on an iPad in Safari, which was failing earlier Iāll make sure itās still working from my Android device, and I suppose since this will affect anything that uses softap-setup-js, we should test configuring from the command line as well.
@indraastra Sounds good, and nice PR! Have you tested on Mac OS?
Yup, forgot to mention that I tested the meteor app on Yosemite and itās working!
Edit: Also tested working on an iPhone 6.
Hey, thanks everyone! This is an awesome thread full of win!
Iāve merged @indraastraās pull request to the softap-setup-js module, and published it as v3.0.2
Here it is on NPM: https://www.npmjs.com/package/softap-setup
Youāre all awesome!
Edit 1:
I lied to you all before, but it is confirmed to work as of 10/16 thanks @indraastra!
softap-setup v3.0.2 is the version being pulled in at http://photonsoftap.meteor.com now as well.
With the proviso you are using a Photon running firmware compiled against the multi-packet fix, expect the Meteor app to work across all browsers (that a sane person might use) now.
This is incredible. I practically jumped for joy when this worked on our iPad.
I seemed to have issue with it on IOS7 but I havenāt looked to see if the issue is my Ionic app or the library yet. Has anyone tested this on older OS versions?
If I remember correctly, I ran into some JS compatibility issues on an iPad running iOS 8 and had to upgrade to iOS 9 to get past them.
Wow, this thread is long, and I donāt understand much of it. Iām still trying to get my head around ANY of the node.js / meteor / stuff that you guys clearly have a great understanding of.
The thing is, Iāve tried following a lot of this without success so far - and itās difficult to know where to put my effort; making a product ( my livelyhood) or learning web app skills ( just to solve one issue).
Essentially I have an almost complete working application in the Photon, but I will ( like many ) need to be selling to customers who will need to set up the wifi credentials, whilst I as a manufacturer retain control of updates etc.
I need to shield them from āPhotonā and use my own website brand to allow set up etc.
Itās this part that is now holding me up.
I really want a browser based setup rather than write android and ios apps.
- The cloud based setup http://photonsoftap.meteor.com/ needs to be customisable, to not read āPhotonā
- I donāt want to use meteor as a branded web address and donāt want to pay for another hosting service if possible
- I failed in getting the browserify to work so far so donāt know what that will do for me. see below
- I believe there is a firmware patch to fix the wiced packets - is this included if I use the web ide and flash a new app?
- I have a hosted website with cpanel access, but donāt know yet if it will run node.js assuming I need it.
For me, this is a minefield and a nightmare as much of the web code/application tech talk is not my core skills ( embedded coding in C ).
Is there / can there be a guide to doing this at a basic explanitory level, after all, the arduino type coding and wiring frameworks was supposed to make it easier to code for the target hardware, yet this fundamental requirement for branding and deploying a product seems to be extraodinarily hard ( for me ).
Problems with getting softap to work:
npm install softap-setup
npm WARN install Refusing to install softap-setup as a dependancy of itself
browserify softap.js -s SoftAPSetup -o softap-browser.js
Error cannot find module ānode-rsaā from ā¦ softap-setup-js.master
Note using Node v4.1.0 is this ok?
Thanks for all the support regardless!!