2-Channel Relay with ESP8266 via WiFi - only get one channel working

I am currently trying to control a 2-Channel Relay Module via WiFi with an ESP8266 using Arduino IDE.
I’ve tested if both relays are working by using a modified version of the “blink” example. They both switched as expected. CH01 is controlled by GPIO1 and CH02 by GPIO3.

Now that I am trying to modify a sketch I found on the web I am having problems controlling both channels. The sketch works absolutely fine if I only use one channel. But anytime i try to implement the second channel (GPIO3) it doesn’t work at all. Somebody please point me the direction to get this working with GPIO1 AND GPIO3. Thank you!

#include <ESP8266WiFi.h>

const char* ssid = "ABCDEFGH";
const char* password = "12345678";

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

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

  // prepare GPIO1
  pinMode(1, OUTPUT);
  digitalWrite(1, 0);
  
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  
  // Start the server
  server.begin();
  Serial.println("Server started @ ");

  // Print the IP address & instructions
  Serial.println(WiFi.localIP());
  Serial.println("To control GPIO, open your web browser.");
  Serial.println("To set GPIO 1 high, type:");
  Serial.print(WiFi.localIP());
  Serial.println("/gpio/1");
  Serial.println("To set GPIO 1 low, type:");
  Serial.print(WiFi.localIP());
  Serial.println("/gpio/0");
  Serial.println("To toggle GPIO 1, type:");
  Serial.print(WiFi.localIP());
  Serial.println("/gpio/2");
}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    delay(100);
    return;
  }
  
  
  // Read the first line of the request
  String req = client.readStringUntil('\r');
  Serial.println(req);
  client.flush();
  
  // Match the request
  int val;
  if (req.indexOf("/gpio1/0") != -1)
    val = 0;
  else if (req.indexOf("/gpio1/1") != -1)
    val = 1;
  else if (req.indexOf("/gpio1/2") != -1)
   val = digitalRead(1);
  else {
    Serial.println("invalid request");
    client.print("HTTP/1.1 404\r\n");
    client.stop();
    return;
  }

  // Set GPIO1 according to the request
  digitalWrite(1, val);
  
  client.flush();

  // Prepare the response
  String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
  s += (val)?"0":"1";

  // Send the response to the client
  client.print(s);
  delay(1);
  Serial.println("Client disonnected");

  // The client will actually be disconnected 
  // when the function returns and 'client' object is detroyed
}

Please post the non-working code. We can't help fix code that we can't see. Which ESP module are you using?

Karma for code tags on first post.

gpio 3 is Serial RX. and io 1 is TX. on common modules with only TX, RX, io 0 and io 2 broke out, they are sometimes used as output.

not all gpio on esp8266 can be used. some are reserved for the flash memory