0

Feather M0 and WiFi manager library?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Feather M0 and WiFi manager library?

by IoTAll on Fri Aug 16, 2019 5:35 pm

Hi!

I am looking for a WiFi manager library working with the M0 feather.
The goal is that when the controller starts, it creates a hotspot, you connect to it, choose the WiFi network you want it to connect, and then the microcontroller connects to it.

Does this kind of library exists?

Thank you!

IoTAll
 
Posts: 133
Joined: Wed May 31, 2017 6:34 pm

Re: Feather M0 and WiFi manager library?

by jdelcamp11 on Sat Aug 17, 2019 4:55 pm

I don't know of a library that does this, but I modified the scanNetworksAdvanced sketch from the wifi101 library to do something like this.
I have attached the modified sketch. It scans for available networks until you type a number into the serial monitor, then connects to the referenced network. After that, I have it starts a webserver. I also included a command (type "R" in the serial monitor) to reset the scan.

It almost works, but I am having trouble pulling the networkID ( SSID[] ) and passcode (pass[]) from the arrays in the arduino_secrets.h. For the moment I have hard coded my SSID[] and PASS[] into arduino_secrets.h. This works.
I always struggle with char arrays. So if someone knows how to do this it would be great.

This should give you a start on what you want to do.
Attachments
arduino_secrets.h
(622 Bytes) Downloaded 6 times
ScanNetworksAdvanced.ino
(11.74 KiB) Downloaded 3 times

jdelcamp11
 
Posts: 155
Joined: Mon Nov 17, 2014 12:30 am

Re: Feather M0 and WiFi manager library?

by IoTAll on Mon Aug 19, 2019 1:47 pm

Thanks will try to work on this!

IoTAll
 
Posts: 133
Joined: Wed May 31, 2017 6:34 pm

Re: Feather M0 and WiFi manager library?

by BryonMiller on Mon Aug 19, 2019 2:07 pm

If you're using WiFi101 see the Provisioning_WiFiWebserver example. Sound to me like it does something pretty close to what you want to do.

BryonMiller
 
Posts: 171
Joined: Fri Mar 04, 2016 10:34 am

Re: Feather M0 and WiFi manager library?

by IoTAll on Mon Aug 19, 2019 4:55 pm

Very nice looks like it!

I just wonder how it can remember the previous Wifi it got connected to as the M0 doesnt have any eeprom memory..

Will try!
Thanks a lot for the tip!!

IoTAll
 
Posts: 133
Joined: Wed May 31, 2017 6:34 pm

Re: Feather M0 and WiFi manager library?

by Forlan86 on Mon Aug 19, 2019 6:39 pm

jdelcamp11 wrote:I don't know of a library that does this, but I modified the scanNetworksAdvanced sketch from the wifi101 library to do something like this.
I have attached the modified sketch. It scans for available networks until you type a number into the serial monitor, then connects to the referenced network. After that, I have it starts a webserver. I also included a command (type "R" in the serial monitor) to reset the scan.
transfers Caen
It almost works, but I am having trouble pulling the networkID ( SSID[] ) and passcode (pass[]) from the arrays in the arduino_secrets.h. For the moment I have hard coded my SSID[] and PASS[] into arduino_secrets.h. This works.
I always struggle with char arrays. So if someone knows how to do this it would be great.

This should give you a start on what you want to do.

Thank you very much for sharing

Forlan86
 
Posts: 1
Joined: Mon Aug 19, 2019 6:38 pm

Re: Feather M0 and WiFi manager library?

by BryonMiller on Tue Aug 20, 2019 8:06 am

IoTAll wrote:I just wonder how it can remember the previous Wifi it got connected to as the M0 doesnt have any eeprom memory..

My understanding is that this memory is actually on the ATWINC1500. This brings about a question of how to clear this memory in the event you think you need to. I think there is a way but not sure what it is.

BryonMiller
 
Posts: 171
Joined: Fri Mar 04, 2016 10:34 am

Re: Feather M0 and WiFi manager library?

by jdelcamp11 on Tue Aug 20, 2019 11:23 am

I finally got my sketch fixed for extracting the ssid and pass.
change the arduino_secrets.h to this
Code: Select all | TOGGLE FULL SIZE
char *knownNets[] = {  // array of known networks                       
                         "network0\0",
                         "network1\0",
                         "network2\0"
                      };
char *passcodes[] = {  // array of passwords                       
                         "passcode0\0",
                         "passcode1\0",
                         "passcode2\0"
                      };
int rows =sizeof(knownNets)/sizeof(knownNets[0]);


then change the void connectSSID to this
Code: Select all | TOGGLE FULL SIZE
void connectSSID(int a) { 
    // get ssid and passcode for selected network
  Serial.print(F("selected = ")); Serial.println(a);
  String ssid1 = {knownNets[1]};
  int ssidlen = ssid1.length() +1;   
  char ssid[ssidlen];   
  ssid1.toCharArray(ssid,ssidlen);
  Serial.print("ssid[] = ");Serial.println(ssid);
 
  String pass1 = {passcodes[1]};
  int passlen = pass1.length() +1;
  char pass[passlen];
  pass1.toCharArray(pass,passlen); 
  Serial.print("pass[] = ");Serial.println(pass);
 
        // attempt to connect to WiFi network:
  while (WiFi.status()!= WL_CONNECTED)
     {
      //*******************************************
      //put code to pull ssid & pass from knownNets and passcodes arrays here
      //*******************************************
      Serial.print(F("Attempting to connect to SSID: "));
      Serial.println(ssid);
        // Connect to WPA/WPA2 network.
      status = WiFi.begin(ssid, pass);
      delay(5000); // wait 5 seconds for connection, then try again
        // note: watchdog will timeout after 16 seconds and reboot Bot
     }
  printWiFiStatus(); // you're connected now, so print out the status:
 } // end of connectSSID  */


This lets you choose from a list of known networks.
If you need to connect to some randon public network, you would need to modify the serial.read section in void startWIFI{} to enter the ssid and pass in the serial monitor. then read and parse this buffer to extract the ssid[] and pass[]. (my routine is only capturing the first character from the serial buffer.)

jdelcamp11
 
Posts: 155
Joined: Mon Nov 17, 2014 12:30 am

Please be positive and constructive with your questions and comments.