Photon softAP usage?

@bitwisekaizen, @hine,

Yes! I have HTTP support for SoftAP Setup in JS nearly functional. I will need to do some additional testing with the latest firmware before I can confirm that it works.

@mebrunet,

Awesome! I took a quick look at what you’re working on and it looks great! One thing we will need to keep in mind is that we need to continue supporting TCP as well as HTTP. I’m happy to work with you on this. I love what you’ve done with the documentation as well. Thank you! I will take a look at the problems you’ve listed here too.

I will post again here when HTTP support is released for the library.

Awesome! I get that you need to keep supporting TCP, but I was hoping to build something isomorphic, which won’t be the case if we use net.socket. I suppose I could have used conditional requires… Is your HTTP support for SoftAP going to be able to run in the browser? If so, I’ll sit tight, if not I’ll keep trucking. Also happy to get on a call at any point this week to avoid parallel dev.

Great! Can’t wait to get my hands on it! Thanks for the reply!

Can I ask a potentially dumb, but non-obvious, question? Is soft ap always available? Or is it just these conditions:

  • initial (clean) config
  • configured wireless unreachable
  • …?

As long as it’s always on when wireless has failed, always at the same default ip then that is great

Not sure what their long term plan is… but given what I’ve seen in the code / experimented with, right now SoftAP is available as long as the device as is in listening mode. Oh, and your Photon needs to be running the latest version of their firmware, which you may need to flash yourself.

@nexxy & @bko

I'm confused by what I'm experiencing...

If if install the lastest Photon firmware from your Github

$ git clone https://github.com/spark/firmware.git
$ git checkout photon_043

then flash with:

$ sudo make PLATFORM=photon clean all program-dfu

The upload runs successfully, and the device goes into listening mode. I can then connect to the access point it creates (Photon-XXXX) and use most of the softAP functionality. e.g. visiting 192.168.0.1/hello returns "SoftAP Setup", /scan-ap sends me a json encoded list of neighboring APs...

However the configure-ap does not behave as expected/documented. For example running the below Python script:

import requests
import json

url = "http://192.168.0.1/configure-ap"

payload = {
"idx":0,
"ssid":"collective",
"sec":4194308,
"pwd":"53ccb6d1f946084a96221923b094a7fcf87834441e5ecae76ef7b9f54339ee1500d25cac3d3bd1baa7d211cc24f2b68a118d8cc7903dde1a5c1a5d27e316667ce40793284201881c92dfa9c1dd4b7ece54dda45da6e6ed86f248b284534dae13c14a456ac638cbfabc8ee9c17caf9dfd63a993f30987dfe05756889d5ac452c1",
"ch":6
}

r = requests.post(url, data = json.dumps(payload))

print r.content

where pwd was encrypted using rsa and the device public key

This prints {"r":0}, then sometimes the device stays in listening mode as expected, but sometimes it blinks red a whole lot and resets (nonetheless having returned "r":0). During this reset the device connects to the WiFi with the credentials from the post.

If the device hasn't reset already, I can then trigger that same flashing red & reset behavior by posting {"idx":0} to "/connect-ap", or simply issuing a GET to "/connect" (which is strange because I didn't see that endpoint handled in the softap_ip.c routes).

Also, it seems like the Content-Length header cannot be omitted in the posts.

Anyway, my question is basically can you point me in a direction that will lead me too more consistent HTTP behavior. I'm hoping to release an MVP in Beta in 3 weeks, and was really hoping to have HTTP connect smoothed out by then.

@mebrunet,

The first thing that comes to mind is making sure you’re using PKCS #1 when encrypting your password. This was a huge mystery for me when writing the SoftAP library initially, since it is not the default padding scheme. Fingers crossed that this is the problem for you; the behavior you describe sounds familiar but this is just a guess.

— Nexxy

@nexxy

Haha, ya I banged my head against the wall for a couple hours with the RSA/PKCS#1, then decided just to copy your softAP-js verbatim. The pwd string above is actually pre-calculated via your library then just manually inserted into the python script. Also given the behavior demonstrated, the device is clearly able to decrypt it (it’s connecting to the wifi… just doing so in a weird way), so I don’t think it’s that.

I’ll see if the softap.py script in the firmware repo yields the correct behavior on my test device and take it from there.

Thanks!

Apologies for persisting, but is it confirmed that the Photon will enter listening mode when no wireless networks are available?

I don’t think that it will, at least not without a time-out. If your wifi drops for a second, your photon would end up being stuck in listening mode.
You can code up this behavior with the various connection calls, to make it as you seem fit. That should give you a bit more flexibility to determine when to enter which mode.

Soft AP in this thread seems to be just about setup, but I want to know if I can use Soft AP as a mini router? Example would be, build OBD2 connection to photon. Have the photon act as a router. My kids get in the car, their tablets connect, a portable wifi hard drive that sits in the trunk is also connected. My kids sit quietly and watch gigs of movies while I drive a long way to visit relatives. As well, I access the Soft AP ip address for the photon to recieve streaming data from the OBD2 connection to be used in a driving app. As a final dream part of this it would be nice to be able to allow my phones data connection to be shared over this.
Is it possible to have Soft AP act as a router?

@mebrunet,

Ack, sorry to hear that! Definitely let me know what you find out or if there’s anything else I can do to help.
I’m working with @mdma to make sure we have the firmware in working order as well.

— Nexxy

I’ve been looking for a way to do something quite straightforward: set the photon to soft AP mode and run my own services (e.g. web server).

The use case is this: I want a user to power the device on, connect a phone or computer to the photon AP, and communicate directly with the device - no internet required. I can then implement my own methods for setting up the wifi credentials, or simply stay in soft AP mode.

If I enter listening mode then the firmware ignores my program and runs its own SoftAP server.
But I want to serve up my own pages. My photon app in this case is all in MANUAL mode, and I don’t need to access the internet or any clouds.

Have I missed something obvious in the documentation?

To clarify, I’m looking for smth like

bool WiFi.configureAccessPoint(const char *ssid, const char *password, unsigned long security)

and functionally the same as wwd_wifi_start_ap() in WICED.

The softap-setup-js library now fully supports HTTP SoftAP setup.

There is one small modifications necessary in the Photon firmware before we can support a 100% browser-based setup, but as soon as this has been published, I will make a thread about it with example code.

Please try out HTTP-based SoftAP setup and let me know how it works.

2 Likes

I should also note that at the time of this writing there is a bug in v0.4.4 of the firmware which will cause the Photon to SOS when using HTTP to send the command to configure the AP. The Photon still connects to the AP you configure, and this will be fixed in a future release.

2 Likes

That’s great, though there are many use cases that won’t be served by this. If you want a product to be functional out of the box, you will want to implement some bespoke services on it in soft ap mode, not just the Photon SoftAP protocol.

To my mind, a simple, manual AP configuration method would have been the first thing to implement, before adding a relatively complex protocol on top. But I understand your priorities.

Are there plans to add something like WiFi.configureAccessPoint() in the future?

@mars, you may want to look at this SoftAP issue:

thanks @peekay123, that’s exactly it.

@nexxy this looks great, thanks. I guess the red flashing LED I was experiencing is the Photon throwing an SOS. I’m getting the same behavior using your library. Do you have any idea what is causing that bug in the firmware and when it will be patched? Maybe @mdma is better suited to answer that?