So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Kowa92
#87929 Hello everyone!

I wanted to expose you the following problem from which i do not come out:

I have an ESP-01S that pilots an ESP8266 Relay v1.0 board (i tested ESP8266 Relay v4.0 board too.. Same problem! :roll: ).
I made the connection on a solderless breadboard. I think both the electrical wiring and the software should have no problems as everything works correctly and never crashes "at zero load".
The problem is that it crashes everytime i connect the NO and COM contacts of the ESP8266 relay board, to any type of AC power supply (both 24 and 230 VAC) that drives a load (for example another relay or fan). After a short time (or immediately) the ESP8266 relay board switches his contact, the ESP-01S always crashes with a reboot and i can't understand why...
I don't think it's a drop down voltage (nor peaks) on the main 3.3V power supply of the ESP-01S because with the multimeter i have not detected anything of abnormal.

- What do you think the problem may be? Has this issue ever happened to someone of you?

I tried to search the web but i did not find anything of useful ..

PS: The ESP-01S reboots for the following reason: "ets Jan 8 2013, rst cause: 4, boot mode: (3,6)"

Thanks to everyone! :)
User avatar
By Kowa92
#87956
pangolin wrote:I think we need to see both the wiring and the sketch you are running


Yeah, this is ESP-01S Relay v1.0 Schematic:

Image

and this is how i linked ESP8266 Relay v1.0 to ESP-01S chip:

Image

The sketch i'm running is that:

Code: Select all/*
    This sketch demonstrates how to set up a simple HTTP-like server.
    The server will set a GPIO pin depending on the request
      http://server_ip/?gpio2=on will set the GPIO0 low,
      http://server_ip/?gpio2=off will set the GPIO2 high
    server_ip is the IP address of the ESP8266 module, will be
    printed to Serial when the module is connected.
*/

/* This sketch is Powered by Kowalski */

#include <ESP8266WiFi.h>

#ifndef STASSID
#define STASSID "xxx"
#define STAPSK  "xxx"
#endif

const char* ssid = STASSID;
const char* password = STAPSK;

const int O0 = 0;
const int O2 = 2;

bool esp_res = false;
unsigned long CN = 0;

// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);

void setup() {
  Serial.begin(115200);

  // prepare GPIO
  pinMode(O0, OUTPUT);
  pinMode(O2, OUTPUT);
  digitalWrite(O0, LOW);
  digitalWrite(O2, LOW);

  // Connect to WiFi network
  Serial.println("\n");
  Serial.print(F("Connecting to: "));
  Serial.println(ssid);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  bool ff = false;
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(F("."));
    ff = !ff;
    digitalWrite(O2, ff);
    delay(500);
  }
  digitalWrite(O2, LOW);
  Serial.println();
  Serial.println(F("WiFi connected"));

  long rssi = WiFi.RSSI();
  Serial.print(F("WiFi signal strength (RSSI): "));
  Serial.print(rssi);
  Serial.println(F(" dBm"));

  // Start the server
  server.begin();
  Serial.println(F("Server HTTP started"));

  // Print the IP address and MAC address
  Serial.print(F("The ESP8266's IP is: "));
  Serial.println(WiFi.localIP());
 
  Serial.print(F("The ESP8266's MAC is: "));
  Serial.println(WiFi.macAddress());
  Serial.println();
}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    if (esp_res) {
      Serial.println(F("Reset cmd launched. Bye"));
      delay(10);
      ESP.reset();
    }
    return;
  }
  Serial.println(F("New client connected"));
  Serial.print(F("CN: "));
  CN++;
  Serial.println(CN);

  //client.setTimeout(5000); // default is 1000

  // Read the first line of the request
  String req = client.readStringUntil('\r');
  //String req = client.readString();
  Serial.println(F("Client's request is: "));
  Serial.println(req);

  // Read the actual state of GPIO
  int state = digitalRead(O0);
  int state1 = digitalRead(O2);
  Serial.print(F("GPIO0 Read: "));
  Serial.println(state);
  Serial.print(F("GPIO2 Read: "));
  Serial.println(state1);

  // Match the request
  if (req.indexOf(F("/?gpio0=on")) != -1) {
    state = 1;
    Serial.println(F("R: switching on GPIO0"));
    }
  else if (req.indexOf(F("/?gpio0=off")) != -1) {
    state = 0;
    Serial.println(F("R: switching off GPIO0"));
    }
  else if (req.indexOf(F("/?gpio2=on")) != -1) {
    state1 = 1;
    Serial.println(F("R: switching on GPIO2"));
    }
  else if (req.indexOf(F("/?gpio2=off")) != -1) {
    state1 = 0;
    Serial.println(F("R: switching off GPIO2"));
    }
  else if (req.indexOf(F("/?resetboard=true")) != -1) {
    Serial.println(F("R: resetting ESP board.."));
    client.print(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\n"));
    client.print(F("<head><title>ESP8266 Web Server</title></head>"));
    client.print(F("<style>html {font-family: Helvetica;}</style>"));
    //client.print(F("<body onload=\"window.open(window.location.href, '_self');\">The ESP8266 is now rebooting.. Please wait.</body></html>"));
    client.print(F("<body><p>The ESP8266-"));
    client.print(ESP.getChipId());
    client.print(F(" is now rebooting.. Please wait.</p><p>Click <a href=\"/\">here</a> in a little while for review the previous page.</p>"));
    client.print(F("<small><p>CN: "));
    client.print(CN);
    client.print(F("</p><p>Powered by <b>Kowalski</b></p></small></body></html>"));
    Serial.println(F("Response sent. Disconnecting from client"));
    Serial.println();
    esp_res = true;
    return;
    }
  else {
    Serial.println(F("Invalid client's request. Do nothing"));
    }

  // Set GPIO according to the request
  digitalWrite(O0, state);
  digitalWrite(O2, state1);
  Serial.print(F("GPIO0 Write: "));
  Serial.println(state);
  Serial.print(F("GPIO2 Write: "));
  Serial.println(state1);

  // read/ignore the rest of the request
  // do not client.flush(): it is for output only, see below
  while (client.available()) {
    // byte by byte is not very efficient
    client.read();
  }

  // Send the response to the client
  // it is OK for multiple small client.print/write,
  // because nagle algorithm will group them into one single packet
  client.print(F("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\n"));
  client.print(F("<head><title>ESP8266 Web Server</title></head>"));
  client.print(F("<style>html {font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}"));
  client.print(F(".button {background-color: #77878A; border: none; color: white; padding: 16px 40px; text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}"));
  client.print(F(".button1 {background-color: #195B6A;}"));
  client.print(F("i {font-size: 19px;}</style></style>"));
  client.print(F("</head><body><h2>ESP8266-"));
  client.print(ESP.getChipId());
  client.print(F(" HTTP Server</h2><form action=\"/\" method=\"get\">"));

  // GPIO 0
  client.print(F("<p><b>GPIO 0</b> - State is: "));
  client.print((state) ? F("<i>on</i>") : F("<i>off</i>"));
  client.print(F("</p>"));

  String content;
  if (state) content = "<input class=\"button\" type=\"submit\" value=\"off\" name=\"gpio0\">";
  else content = "<input class=\"button button1\" type=\"submit\" value=\"on\" name=\"gpio0\">";

  client.print(content);
 
  //GPIO 2
  client.print(F("<p><b>GPIO 2</b> - State is: "));
  client.print((state1) ? F("<i>on</i>") : F("<i>off</i>"));
  client.print(F("</p>"));

  if (state1) content = "<input class=\"button\" type=\"submit\" value=\"off\" name=\"gpio2\">";
  else content = "<input class=\"button button1\" type=\"submit\" value=\"on\" name=\"gpio2\">";

  //client.print(content + F("</form>"));
  client.print(content);
  client.print(F("<br><br><button onclick=\"location.reload(true);\">Reload</button>"));
  client.print(F("<br><br><small><a href=\"javascript:if(confirm('Are you sure to reboot ESP8266-"));
  client.print(ESP.getChipId());
  client.print(F(" Module?')){window.open('/?resetboard=true', '_self')};\">Reset ESP</a>"));
  client.print(F("</form><p>CN: "));
  client.print(CN);
  client.print(F("</p><p>Powered by <b>Kowalski</b></p></small></body></html>"));

  // The client will actually be *flushed* then disconnected
  // when the function returns and 'client' object is destroyed (out-of-scope)
  // flush = ensure written data are received by the other side
  Serial.println(F("Response sent. Disconnecting from client"));
  Serial.println();
}