List Discovered Wifi Networks

Hi, I am new to spark and am coming from an Arduino background. I am having trouble finding what I need in the spark documentation and so am wondering if what I want to do is possible.

I would like to be able to get the spark to scan for nearby wifi networks (SSID, security config) and report its findings so that I can display the list on an LCD screen. Once listed, I would like to allow the user to select a network and enter the pass code for it, then get the core to connect to that network.

I have achieved this on an Arduino Mega with a wifi shield using serially transmitted commands to the wifi shield then reading the result into an array, the LCD stuff is not relevant to this question as I have nailed that already.

However, I’m not sure how the core behaves, maybe I cant talk directly to the wifi chip I don’t know. I was hoping there would be some kind of wrapper class for commands to the core that would expose this functionality to us coders as standard. I had hoped that the core would make it easier to play with the wifi chip that the arduino was. If anyone could expand this for me I’d be most grateful.

I have found similar threads on here but nothing that seemed helpful in regards to this.

Thank you, Rick.

You can put the core in Listening mode and press w to send Wifi Credentials on the core.

I don’t think we can be scanning the Wifi networks around the :spark: core and list them out. But maybe i’m wrong on this.

Hmm, if that’s true then it kinda sucks.

I’m building a device that I need to take to different locations and be able to hook up to the wifi in that area.

These spark cores are not simply an arduino with built in wifi are they, or maybe they could be with the correct firmware.

I really need a library that will enable easy access to the wifi chip so I can

  • connect/disconnect (in code)
  • list available networks
  • report signal strength.

Is there any way I can write such a library or that someone out there would be interested enough to consider doing this, is it even technically possible?

I could be mistaken, but I’m fairly certain I once saw a video from @timb in which he had a Core displaying wifi networks on a display. I believe he wrote some sort of sketch for it, of which you should be able to find more info here: https://community.spark.io/t/timbs-project-sprint-list/3075/26
Maybe Timb can elaborate some more, if this is indeed possible(?)
Good luck!

Hi @rickpbush

What you want to do is totally possible with the Spark core, but it is not setup to work this way out of the box. One reason for that is that Spark cloud assumes you are WiFi connected so anytime you move away from that notion, you are moving into advanced territory.

The Network class has an RSSI method that @timb put in that does a lot of what you want. If you look at the code here:

https://github.com/spark/core-firmware/blob/master/src/spark_wiring_network.cpp

you will see that it calls a scan routine in the CC3000 driver to look for WiFi networks and find the one that matches the current SSID and returns the results for that. You can (and Tim has in that other post) use the other networks and RSSI data.

Connecting and disconnecting in code is possible but it is an advanced maneuver since you will have to stop the spark cloud.

One other point, the CC3000 can store up to 7 WiFi profiles and so if you are only ever going to be on 7 or fewer different networks, you can do that more easily.

You can totally list out networks around your core! I started hacking on this for fun, here’s my example app:

https://gist.github.com/dmiddlecamp/11294083

Enjoy!
David

1 Like

Wow, that is excellent, I did find it hard to believe that this was not possible. I think that coming from Arduino into this ‘Spark Cloud’ stuff is a bit of a culture shock but with the help of the forum I think I can get into it :slight_smile: Thanks guys, your brilliant and your help is valued massively.

3 Likes

Yup, I did this a few months ago. Check it out!

I’d post the code, unfortunately, I must have accidentally deleted my sketch in the Sparkulator! :frowning:

I don’t suppose there’s a way to undelete stuff server-side, is there?

This is a pretty simple and cool class!

One thing I’ve noticed is that after calling Network.RSSI() several dozen times, all the function returns is 2, the timeout value every time.

Is there some way to improve this?

In the main loop, I can repro regularly with just:

void loop()
{
    Serial.print("RSSI:\t");
    Serial.println(Network.RSSI());
}
delay(5000);

Sooner or later “RSSI: -44” becomes “RSSI: 2” until the core gets powercycled. Maybe it’s just the way I’m doing it?

Hi @BlueLou

I think you must have meant for the delay(5000); to be inside that last curly-brace, right? Maybe that’s the problem?

Otherwise I am not sure why that would fail. It is calling the underlying CC3000 driver function.

Can you say how long it takes to fail? I put your program together with a serial display on a core and it ran for quite a while without problems–over one-hundred 5 second rounds.

Yeah, trying putting your delay inside the main loop. During development of the RSSI code, I ran it in a continuous loop every 5 seconds and it ran for several days with no issues.

Hey @timb,

I can try to help you out with undeleting stuff if you need it. I can’t guarantee I can help, but I can dig through old database backups if you tell me when you last saw it / what it was called, etc.

Thanks,
David

Yeah, I totally botched that code paste. The delay() is inside my loop…

Only thing I can think of are misbehaving core, or still a code issue on my part.

I’m not defining a #include for any external libraries, and my code is being built and run via the web ide and 2.1 firmware, apparently:

Spark Firmware v0.2.1
core-firmware efaf31 Apr 18
core-communication-lib 6d136f Apr 18
core-common-lib ee7fca Apr 18

Anything interesting about that?

No, nothing is remarkable there. I also used the webIDE for my test.

When it fails, do you get anything other than breathing cyan on the main LED?

Are you in a spot with lots of wireless networks? I have two networks right at hand for my testing and maybe 1 or 2 others that are sometimes in range for the core from the neighbors.

Brilliant, thanks guys. I’m going to implement this but I’m guessing that because I’m going to have to disconnect from the cloud to do it then I will need to get my act together and sort out some kind of IDE locally to program the core rather than using the web IDE. This is something I’d rather be doing anyway but because I only received my cores a week ago I’m still on a bit of a learning curve.

Hi @rickpbush

Start your local build research with this post, then you can follow up here in the forum for the many different IDE options: