Setup WIFI on your Arduino MKR devices requires some preparation and secure information mostly stored in your arduino-secret.h files.
This library makes it easy: one time credentials entry, connect & forget. no need to code it in your.ino or.h fileGitHub
The EasyWiFi library can be found on GitHub : https://github.com/javos65/EasyWifi-for-MKR1010
Here it will be maintained, check the GitHub for the latest repository.Library
Besides the EasyWiFi.h inclusion, this project requires the WifiNINA.h libraries. Be sure to use the latest version (1.4.+) as older version don't support the flash storage very well.
The library has some debug switches in EasyWiFi.ccp that you can turn on to look by the serial-interface for debugging info : #define DBGON (for general debug) and #define DBGON_X (for packet info)Class Functions
EasyWiFi is a new Class, where you have the following function calls:
byte apname(char * name);
void seed(int value);
.start() is the main function, this follows the following procedure:
- 1. read credentials from Flash drive (uBlox NINA W10 module)
- 2. (if no credentials, us pre-programmed ones, this is still available)
- 3.> Try to Log into WiFi Network,
- 3a. if connection is ok, start returns to your program
- 3b. if no connection, start opens a Captive Portal by means of an Access Point.
- 4. log into this AP, and open the portal: enter your credentials and submit.
- 5. credentials are saved to Flash drive, and try to login : step 3.>
There is no max retries or timeout, if no correct credentials are entered, AP will stay alive... sorry -> ADAPTED !!
.erase() : erases your credentials from Flash Drive
.apname() : set custom name of your Portal Access point
.seed() : set the seed of the Cypher algorithmColor RGB led
The RGB led on the WifiNina module shows WiFi status indication (Mkr1010 only):
- GREEN: Connected
- BLUE: (Stored) Credentials found, connecting...
- YELLOW: No Stored Credentials found, connecting...
- PURPLE: Can't connect, opening AP for credentials input
- CYAN: Client connected to AP, wait for credentials input...
- RED: Not connected / Can't connect, .start() is stopped, return to program
storing the data on the Flash drive will create a file with byte/character content. This file stays on your MKR1010 module, even if you reprogram the part, so theoretically its there forever. To avoid unwanted reading of your password and SSID, its Cyphered a little bit. Its not a crypto-proof algorithm, but it hustles the characters into a unreadable content.
In the examples of this library there is a ".ino" code example how to read and write the crypto file.Captive Portal
The trick with the AP is that its forcing the connecting Smartphone to open the Portal Webpage. For more info on this feature, see my other Project on this topic:
Hackster.IO: captive-portal-for-wifi-apTo be improved:
Improvements in progress:
- Build in Max time-out for number of WiFi connect retries (done)
- Add RGB led coloring during WiFi setup (done)
- Build function to set the AP WiFi channel
- Build function to define your own storage filename
- Extend the stored IP to a known priority-list, and match these with the found WiFi-networks for easier access by dynamic location use of your Arduino
- Implement more complex cyphering or crypto.
- Make the library compliant with other WiFi shield : issue is the storage function that is by example not able on the MKR1000 series
- Test the project on Arduino Nano 33 with uBlox Nina, test on ESP32 shields - done, works, but no RGB led.