Chat freely about anything...

User avatar
By Meph
#57308 hi, im facing a problem that i cant figuer out why does this, im new into messing arround with ESP so im got no clue why doing this, so any help would be apreciated.
i plug my GPIOS to a relay, all works fine, but the problem is if i power down and turn back power on, than it cant find my ESP in wifi network, but if then i remove GPIO pins from the relays and then power back on it finds my ESP device in network.

the code im using is:
Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

MDNSResponder mdns;

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

ESP8266WebServer server(80);

String webPage = "";

int gpio0_pin = 0;
int gpio2_pin = 2;

void setup(void){

  webPage += "<h1>HOME CENTRAL AUTOMATION</h1><p>RELAY 1 <a href=\"socket1On\"><button>ON</button></a>&nbsp;<a href=\"socket1Off\"><button>OFF</button></a></p>";
  webPage += "<p><b>RELAY 2<a href=\"socket2On\"><button>ON</button></a>&nbsp;<a href=\"socket2Off\"><button>OFF</button></a></b></p>";
 
  // preparing GPIOs
  pinMode(gpio0_pin, OUTPUT);
  digitalWrite(gpio0_pin, LOW);
  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("/socket1On", [](){
    server.send(200, "text/html", webPage);
    digitalWrite(gpio0_pin, HIGH);
    delay(1000);
  });
  server.on("/socket1Off", [](){
    server.send(200, "text/html", webPage);
    digitalWrite(gpio0_pin, LOW);
    delay(1000);
  });
  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();
}

i dont think it has nothing to do the code.
any toughts in what could be
User avatar
By martinayotte
#57328 You are using GPIO2/GPIO0 to drive your relays, those pins are used for the bootloader process at startup which needs to be both HIGH to execute your code.
You need to be sure the HIGH still there at startup, so depending how your wired your relay driver, it prevent that. Show us your wiring, we will be able to provide hints ...