Configure wifi (only) via website and/or app: please help

Hi there. I recently replied to this topic (redacted due to double posting policy), asking for help with writing a website that can configure wifi on a new Particle – but then I realized that topic was in the “General” category. So I’ll ask it here, too…

Has anyone successfully figured out a way to write a website that can allow a customer to configure wifi on their brand new Particle-based product?

Thanks,
Dan

Hi All.

I just read all 256 posts to this topic. Most of the action occurred last August or so. The firmware versions on new Photons is 0.4.9. Is there a newer version of @mebrunet’s code to match? Is there something else that people are using now? I’d like to either:

  1. Have my customers connect to the soft AP on their new device and configure wifi.

OR

  1. Have my customers connect to my website and configure wifi.

Either way is fine. I’m just at a loss as to how to start.

Thanks,
Dan

This might be interesting in this regard
https://github.com/spark/firmware/pull/906

That is milestoned for 0.5.0, which should go public not too far from now.
https://github.com/spark/firmware/milestones

2 Likes

Seems like you need this: https://github.com/spark/softap-setup-js ?

@ScruffR – thanks. I’ll keep an eye out for that update.

@harrisonhjones – I tried that last night. I followed the instructions to browserify it into softap-browser.js, then tried the following code:

<!doctype html>
<html lang="en">
<head></head>
<body>
  <script src="softap-browser.js"></script>
  <script>
      
    var sap = new SoftAPSetup();
    sap.deviceInfo(callback);

    function callback(err, dat) {
        if (err) { throw err; }
        console.log("Device ID: %s, claimed: %s", dat.id, dat.claimed ? "yes" : "no");
    };
  </script>
 </body>
 </html>

And in the console log, I got: “TypeError: opts is undefined”.

I tried again with the declaration changed to

var sap = new SoftAPSetup({ "protocol": 'http', "timeout": 2000 });

But that gave the error “Error: Implemented in protocol specific class”

Any idea as to what I’m doing wrong?

Thanks,
Dan

I can’t quite look at this right now so my help is limited. The folks over @ Hook (gethook.io) have a working web device setup. Here is their js file: http://www.gethook.io/web/assets/js/softap-browser-min.js Try using it since I know it works :stuck_out_tongue: and let me know how that goes.

I tried the same lib independtly today and gets similar results.

Without specifying http I get "Cannot read property ‘keepAlive’"
With http I get the implemented in protocol specific class error :confused:

And the meteor app website is down, anyone know of a public website to setup photon wifi thats working atm ?

Hi

You can try my copy here:

   http://neighbour.meteorapp.com/

Works well for the small number of devices I have tried do far.

Regards

Kevin

Mora. I’ll try to put together a proof of concept in the next day or so. Can you shoot a quick email to support@particle.io so I can track it?

@harrisonhjones – That was it. Thanks! My browserification process must have gone wrong. The link you provided to the softap-browser-min.js at gethook worked perfectly. What I tested was:

  1. get the deviceInfo. This returned the ID and claim flag.

  2. get the publicKey

  3. call configure (I used a router that doesn’t broadcast its SSID so I was hoping it would work. It did)

  4. call connect. It rebooted and quickly went through the process of connecting and was breathing cyan within seconds.

What I did NOT do yet was call setClaimCode. I’m not sure how it works. The docs on github say it requires a claimcode that can be gotten via the Particle API, but I don’t see a function that returns a claimcode. Any idea how the claiming is handled?

For reference, here is my test code:

<!doctype html>
<html lang="en">
<head></head>
<body>
  <script src="softap-browser-min.js"></script>
  <script>
      
      //var sap = new SoftAPSetup();
      var sap = new SoftAPSetup({ "protocol": 'http', "timeout": 2000 });
      
    sap.deviceInfo(callback);
    function callback(err, dat) {
        if (err) { throw err; }
        console.log("Device ID: %s, claimed: %s", dat.id, dat.claimed ? "yes" : "no");

    
    sap.publicKey(callback);
    function callback(err, dat) {
        if (err) { throw err; }
        console.log(dat);

    sap.configure({
        ssid: "something",
        security: "wpa2_mixed",
        password: "somethingelse",
        channel: "6"
    }, callback);
    function callback(err, dat) {
        console.log("Device is configuring");

    sap.connect(callback);
    function callback(err, dat) {
        console.log("Device is attempting to connect to the AP...");
    };
};
};
};

  </script>
 </body>
 </html>

Thanks again to everybody.
Dan

1 Like

Glad you got it working. Take a look here: https://docs.particle.io/reference/api/#create-a-claim-code

I’m in the same boat when it comes to confusion with claiming process.
Here’s what I do:

  1. Create a customer Implicit
    1.1. registration form - submit form to particle endpoint with organization fields specified
    1.2. emerge at my https page where I save token from url hash to cookie
  2. Create a claim code - nothing organization specific there that I could find.
    2.1 Getting response like {“claim_code”: “REALLY LONG STRING HERE”, “device_ids”: []}
    2.2 redirecting to non-https sub-domain with claim code as url parameter
  3. SoftAp using above mentioned softap-browser-min.js
    3.1. wait for user to reconnect to WiFi to device
    3.2 key/id/scan/configure - all coming back with expected results
    3.3 setClaimCode with the code from URL
    3.4 connect request and wait for user to reconnect to interwebs (breathing syan)
  4. Claim - no organization related params here
    4.1 redirecting back to https domain with id in the url parameters
    4.2 call to endpoint without “request_transfer” param get error that parameter is needed even though in dashboard device shows as not associated with any customers, with “request_transfer” param getting 403 forbidden {“ok”:false, “errors”: []}

Anything I’m doing wrong here? @harrisonhjones @ScruffR ?

I see, but you used the browserification command from the spark github right?
So theres an issue in that repository.

@dperrigan,
I used the working version of browserified JS file linked here by @harrisonhjones. I’m getting device successfully connected, just not assigned to customer account.

Its working with the hook copy of the js file, so in light of the coming builtin feature in 5.0, I dont think this is a priority issue.

If you want to debug it though, the examples on github is enough to show the error, when the js file is built using the instructions on the same page.

Maybe it would be preferable to offer the js file as a download, instead of users having to browserify it manually.

By “it” do you mean network setup alone or including device claiming into customer’s account? With Hook’s working copy of softap-browser-min.js I succeeded in implementing the network setup, but no such luck with claiming.

I’ll keep banging at it, but if anybody has a working sample of the browser based setup process that includes claiming the device into customer’s account I’d really appreciate sharing it or describing the steps.

Sorry, I didnt use claim, just setting the wifi network.