-->
Page 1 of 1

WiFiManager + Webserver

PostPosted: Thu Jan 26, 2017 4:47 am
by Reactionic
I'am trying to control an LED over wifi but each place has its own wifi configuration, so that i have decided to use WiFiManager library. Both WiFiManager and webserver works stable individually. When I add WiFiManager to webserver, esp8266 keeps resetting itself every 10sec. Here is the code: what may cause that? :|
Code: Select all
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <DNSServer.h>
#include <ESP8266mDNS.h>
#include <WiFiManager.h>

MDNSResponder mdns;

// Replace with your network credentials
//const char* ssid = "myWiFi";
//const char* password = "password";

ESP8266WebServer server(80);

String webPage = "";

int gpio2_pin = 2;

void setup(void){
  Serial.begin(115200);
  WiFiManager wifiManager;
  //wifiManager.resetSettings();
  wifiManager.autoConnect("AutoConnectAP");
  Serial.println("connected...yeey :)");
 
  webPage += "<h1>ESP8266 Web Server</h1>";
  webPage += "<p>LED Lamba <a href=\"socket2On\"><button>YAK</button></a>&nbsp;<a href=\"socket2Off\"><button>SONDUR</button></a></p>";
 
  // preparing GPIOs
  pinMode(gpio2_pin, OUTPUT);
  digitalWrite(gpio2_pin, LOW);
 
  delay(1000);
  Serial.begin(115200);
  //WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
//  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
 
  if (mdns.begin("esp8266", WiFi.localIP())) {
    Serial.println("MDNS responder started");
  }
 
  server.on("/", [](){
    server.send(200, "text/html", webPage);
  });
  server.on("/socket2On", [](){
    server.send(200, "text/html", webPage);
    digitalWrite(gpio2_pin, HIGH);
    delay(1000);
  });
  server.on("/socket2Off", [](){
    server.send(200, "text/html", webPage);
    digitalWrite(gpio2_pin, LOW);
    delay(1000);
  });
  server.begin();
  Serial.println("HTTP server started");
}
 
void loop(void){
  server.handleClient();
}

Re: WiFiManager + Webserver

PostPosted: Fri Feb 17, 2017 10:50 pm
by tusharpc
https://gist.github.com/tzapu/ecc0759829d30d5a6152

try this... i'm yet to add actual gpio functionality but it's responding well to the url requests and sending text back...