Network Scanning possible with Photon?

I was wondering, is there a way to have the Photon scan for nearby WiFi networks?

Let me explain, I’m interfacing a touchscreen with a Photon. I would like this touchscreen to display nearby WiFi networks (scanned by the Photon), allow someone to select the one they want, and then type in the password and boom… they are connected. At this current moment I am only caring about the Photon aspect of this build and that’s what brings me here. All the documentation I have stumbled upon hasn’t given me what I’m looking for (or maybe it has and I just overlooked it).

I looked at other threads and none of them seemed to line up with what I am looking for.

Thanks
Korona

https://docs.particle.io/reference/firmware/photon/#scan-

4 Likes

wow…i feel dumb. Thanks @kennethlimcp . I must be losing my mind

(I’m feeling pretty dumb myself, but here goes …)

Okay, so ‘scan()’ shows, say 5 networks. How can I choose the one I want? ‘WiFi.connect()’ doesn’t take an argument. (Let me restate that: the doc for ‘WiFi.connect()’ doesn’t show it taking any arguments.)

Which leads to a closely related question: I have several Photons, each with credentials for two networks. The two networks usually aren’t on at the same time, but sometimes they are. How does the firmware choose one? (And how can I force it to one or the other?)

Thanks in advance.

-R

It tries to connect to the last added network first, if it’s there it will connect, if not it will try the next one and so on.

Currently there is no API to tell the device which of the stored networks to connect to.

Try combining these two?
https://docs.particle.io/reference/firmware/photon/#scan-
https://docs.particle.io/reference/firmware/photon/#setcredentials-

connect()

Attempts to connect to the Wi-Fi network. If there are no credentials stored, this will enter listening mode. If there are credentials stored, this will try the available credentials until connection is successful.

To use that, you'll need to have credentials stored, which in can try. Use the above mentioned docs to set those.

Thank you both. I’ve looked for an API for this and had pretty much concluded that it didn’t exist. But it’s good to have it confirmed that it’s not there. As for the ‘scan’ + ‘setCredentials’: very clever.

Again, thanks for the quick replies.

1 Like

So the scan() and setCredentials() used together is a very cleaver way of doing this. When looking at the documentation for scan() it states we provide the array WiFiAccessPoints. Is this basically saying that we set up a structure that will contain the scanned information. Kind of like this:

struct WiFiAccessPoints {
char SSID[33];
uint8_t BSSID[6];
SecurityType securityType;
uint8_t channel;
int RSSI;
}

Now going with this (this question is more directed toward @ScruffR) whats the best route to take to move this data (at least the SSIDs) into buffers to be able to set the text on the Nextion to be displayed?

Once I can get this to work I will be working on making it so a user can select the ap they want to connect to (or at least add to the credentials) by using an on-screen keyboard and setCredentials()

I guess I’m just looking for a little more explanation on how exactly this works and it executed. Referring to the link below

https://github.com/spark/firmware/issues/567

Yup, you found the answer :+1:

Previously you could have used memcpy() (or field by field) to transfer the data from the internal buffer over to your own local buffer.

@Korona75 @ScruffR @kennethlimcp @randyenger @Moors7

thinking about this more, is there a way to use the WiFi.scan to not only scan for the SSID with the strongest RSSI but also take the value that it returns with, presumably the negative int closest to zero, and then pipe that to a WiFi.connect?

Cheers
Mark

The Photon chooses the strong AP (i think) and connects so this might not be required?

I believe the photon will try the newest added credentials first then try the next newest, ie:

WiFi.setCredentials( SSID1, ... ) ;
WiFi.setCredentials( SSID2, ... ) ;

The photon will try SSID2 and move on to SSID1 if it can’t find the first, regardless of signal strength. The Core behaves differently, however.

@MarkyD if you want to do that, you need to clear creds with WiFi.clearCredentials() then add the network you prefer to connect with using WiFi.setCredentials( ... )

Thanks @kennethlimcp @jakeypoo

From what I’m guessing on the OP’s post, the photon is being used to identify new SSIDs which may not be stored in memory. It makes sense that after a scan it would connect to the strongest one (if this is the default action) as you can have a WiFi.setCredentials with a default username and password over x number of wifi networks.
However, if the OPs project is scanning and then attempting to connect to unknown wifi networks then the WiFi.scan > strongestRSSI > WiFi.connect might be the best way??

What are your thoughts?

I wonder how you can have the password sent to the Photon if it is a new SSID using WiFi.setCredentials() even though the signal is the strongest?

@kennethlimcp

I can only think that you could specify a WiFi.setCredentials(password) as a generic login to all SSIDs or authenticating through MAC. This would mean manually creating an account or allowing via MAC address.

Interesting. Sounds like using a mix of multi-threading, wifi scanning and then setting the credentials might be a good path for you to try out :wink: