×

การติดตั้งไลบารีช่วยเชื่อมต่อไวไฟด้วย WiFiManager

การติดตั้งไลบารีช่วยเชื่อมต่อไวไฟด้วย WiFiManager

การติดตั้งไลบารีช่วยเชื่อมต่อไวไฟด้วย WiFiManager
1. เปิด Aduino IDE

2. คลิกที่เมนู Sketch > Include Libraries…. > Manage Libraries…

WiFi-01

3. พิมพ์คำว่า wifimanager  เพื่อค้นหาไลบรารี WiFiManager

4. คลิกปุ่ม Install เพื่อติดตั้ง

WiFi-02

5. ทดสอบด้วยโค้ดตัวอย่าง
File > Examples > WiFiManager > AutoConnect

WiFi-03

ตัวอย่างโค้ด

===============================
#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino

//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>         //https://github.com/tzapu/WiFiManager

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);

//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around
    WiFiManager wifiManager;
wifiManager.setTimeout(180); 
//reset saved settings
//wifiManager.resetSettings();

//set custom ip for portal
//wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));

//fetches ssid and pass from eeprom and tries to connect
//if it does not connect it starts an access point with the specified name
//here  “AutoConnectAP”
//and goes into a blocking loop awaiting configuration
wifiManager.autoConnect(“AutoConnectAP”);
//or use this for auto generated name ESP + ChipID
//wifiManager.autoConnect();

//if you get here you have connected to the WiFi
Serial.println(“connected…OK”);
}

void loop() {
// put your main code here, to run repeatedly:

}

======================================================
ทำการคอมไพล์โค้ด

WiFi-03-2