Hai everyone,
i need to configurre wifi for esp8266 using wifi manager so i have a idea to add custom html to give options of selecting IP mode dynamic or static then if static IP mode get IP,gateway, Subnet mask in webpage.
but I tried so many time i could not complete it.
please help me to do it....
Show us the code where you got the best result.
RandomNerd made some instructions that sound like your question...
#include <ESP8266WiFi.h>
#include <WiFiManager.h>
#define LONG_PRESS_TIME 5000
bool shouldSaveConfig = false;
int buttonPin = 12; // PIN 12 for Smart Configuration
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
pinMode(buttonPin, INPUT_PULLUP); /************************ set the WiFi reset button as INPUT ************************/
digitalWrite(buttonPin, LOW); /******************* During start up the PIN is LOW state after pressing it this becomes HIGH *********/
WiFiManagerParameter custom_ip("custom_ip", "Custom IP", "192.168.1.100",16); //default IP Address
WiFiManagerParameter custom_gateway("custom_gateway", "Gateway", "192.168.1.1",16); //Default Gateway IP Address
WiFiManagerParameter custom_subnet("custom_subnet", "Subnet Mask", "255.255.255.0",16); //Default Subnet Mask
WiFiManager wifiManager;
IPAddress ip, gateway, subnet;
ip.fromString(custom_ip.getValue());
gateway.fromString(custom_gateway.getValue());
subnet.fromString(custom_subnet.getValue());
WiFi.config(ip, gateway, subnet);
wifiManager.setSTAStaticIPConfig(ip, gateway, subnet);
wifiManager.addParameter(&custom_ip);
wifiManager.addParameter(&custom_gateway);
wifiManager.addParameter(&custom_subnet);
wifiManager.autoConnect("AP Mode");
if (!wifiManager.autoConnect("AP Mode")) {
Serial.println("failed to connect and hit timeout");
delay(3000);
//reset and try again, or maybe put it to deep sleep
ESP.restart();
delay(5000);
}
// if we get here, we are connected to WiFi
Serial.println("WiFi connected");
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
Serial.print("Custom IP: ");
Serial.println(custom_ip.getValue());
Serial.print("Gateway: ");
Serial.println(custom_gateway.getValue());
Serial.print("Subnet Mask: ");
Serial.println(custom_subnet.getValue());
}
void loop() {
static unsigned long buttonPressStartTime = 0;
static bool buttonPressed = false;
if (digitalRead(buttonPin) == HIGH) {
if (!buttonPressed) {
Serial.println("AP Button is Pressed");
buttonPressed = true;
buttonPressStartTime = millis();
}
if (millis() - buttonPressStartTime > LONG_PRESS_TIME) {
WiFi.disconnect();
WiFi.mode(WIFI_AP);
WiFi.softAP("AP Mode");
WiFiManager wifiManager;
wifiManager.startConfigPortal("AP Mode");
}
}
else {
//Serial.println("AP Mode is Failed");
buttonPressed = false;
}
}
Please edit your code to add tags <code/>
You can't change the state of a button using digitalWrite
.
pinMode(buttonPin, INPUT_PULLUP);
digitalWrite(buttonPin, LOW);
This example does what do you want.
i added code tag now check it..
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.