Adding Captive Wi-Fi Interface to ESP8266 Project

综合编程 2016-04-10

When the first time I did an electronic project by using cheap ESP8266-01 Wi-Fi module, I always hard coded the SSID target and its password into the source code. I did not take it for granted that process. It was obviously impractical to deploy the hard coded SSID and password into a production system. Hence, I searched the solution how to setup SSID and password with a user-friendly way. I got it. I should make captive Wi-Fi interface, so I can setup and scan the available SSID for the ESP8266 via mobile phone or desktop browser. Luckily ESP8266 can be used as AP (Access Point) station and also AP client. Therefore, making a captive Wi-Fi interface is possible.

The flow of the system is:

  1. Check whether an SSID and password exist in the memory
  2. If there is no existing SSID and password, ESP8266 will change into AP station mode and run as web server
  3. Connect a browser capable device to the ESP8266
  4. Scan and login to any available SSID via the captive Wi-Fi window
  5. When it successfully log in, the ESP8266 will become an AP client again.

I found a library to achieve that objective easily. Its name is WiFiManager . It is very easy to install and to use, you can just follow the instruction in its Github. Here is the sample code that I use via Arduino IDE.

#include  
#include 
#include 
#include 
#include  
 
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
 
  WiFiManager wifiManager;
  wifiManager.setBreakAfterConfig(true);
  if (!wifiManager.autoConnect("Asep ESP8266", "asepbagja")) {
    Serial.println("failed to connect, we should reset as see if it connects");
    delay(3000);
    ESP.reset();
    delay(5000);
  }
 
  //if you get here you have connected to the WiFi
  Serial.println("connected...yeey :)");
 
 
  Serial.println("local ip");
  Serial.println(WiFi.localIP());
}
 
void loop() {
  // put your main code here, to run repeatedly:
}

Tags:esp8266, iot

责编内容by:Asep Bagja Priandana (源链)。感谢您的支持!

您可能感兴趣的

Quicksilver + ServiceAPI: the authentication issue... It’s possible to run Quicksilver and ServiceAPI on a same site, with some modif...
books chapter four Keep it simple. coders Moving back in time, before there was JSON there was ...
Talk: Overcoming Impostor Syndrome at LWT 2018 Note: this is the transcription of the talk I've done at the Lesbians Who Tech ...
Password Strength Estimator Password to test: Note This is an online demo of Dropbox’s zxcvbn algori...
Even quicker byte count Last time, I thought I’d sped up line counting (which both xi -rope and r...