Adding Captive Wi-Fi Interface to ESP8266 Project

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.

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

Tags:esp8266, iot

稿源:Asep Bagja Priandana (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » Adding Captive Wi-Fi Interface to ESP8266 Project

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录