user71205: I have a webserver configured on my esp8266 with is set to fire off electrical relay0 on my 8 port relay board.
The device initializes relay0 perfectly and without errors.
But when I configure the second relay1, i get no response from my second url.
//note, when you write to low, you turn the switchport on. It's backwards for some reason
#include <ESP8266WiFi.h>
#define statusLed 2   // built-in led for the ESP8266-12

const char* ssid = "myssid";
const char* password = "mypass";
 
int switchPin0 = 16;
int switchPin1 = 5;
int switch0;
int switch1;

WiFiServer server(80);
 
void setup() {
  Serial.begin(115200);
  delay(10);
 
  pinMode(statusLed, OUTPUT);
  pinMode(switchPin0, OUTPUT);
  digitalWrite(switchPin0, HIGH);

  // 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(".");
  }
  digitalWrite(statusLed, HIGH);
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Start the server
  server.begin();
  Serial.println("Server started");
 
  // Print the IP address
  Serial.print("Use this URL : ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
 
}
 
void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
 
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
 
  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);

  client.flush();

  // Match the request
 
  int value = HIGH;
  if (request.indexOf("/SWITCH=0") != -1){
    digitalWrite(switchPin0, LOW);
    digitalWrite(statusLed, LOW);   // blink led
    delay(1);
    digitalWrite(statusLed, HIGH);
    //set water pump time here
    delay(8000);
    digitalWrite(switchPin0, HIGH);
    value = HIGH;
    ++switch0;
  } else if (request.indexOf("/SWITCH=1") != -1){
    digitalWrite(switchPin1, LOW);
    digitalWrite(statusLed, LOW);   // blink led
    delay(1);
    digitalWrite(statusLed, HIGH);
    //set water pump time here
    delay(8000);
    digitalWrite(switchPin1, HIGH);
    value = HIGH;
    ++switch1;
  } else {

    }
 
  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
 
  client.print("Switch pin is now: ");
 
  if(value == HIGH) {
    client.print("Off");  
  } else {
    client.print("On");
  }
  client.println("<br><br>");
  client.println("Switch 0");
  client.println("Click <a href=\"/SWITCH=0\">here</a>  to send a measured amount<br>");
  client.println("Number of times plant 0 has been fed is ");
  client.println(switch0);
  client.println("<br><br>");
  client.println("Switch 1");
  client.println("Click <a href=\"/SWITCH=1\">here</a>  to send a measured amount<br>");
  client.println("Number of times plant 1 has been fed is ");
  client.println(switch1);
  client.println("</html>");
 
  delay(1);
  Serial.println("Client disconnected");
  Serial.println("");
  digitalWrite(statusLed, LOW);   // blink led
  delay(1);
  digitalWrite(statusLed, HIGH);
 
}

my counter will update, but the relay pin never fires for relay1. relay0 works fine. I can swap the ports and then the second relay will work and not the first. I just can't manage both.
How do I get a second (or more) relay ports to initialize via webpage?

user62523: It looks like you forgot to initialize switchPin1 to be an output.
Add the following to your setup() (for example, right after the corresponding initialization commands for switchPin0):
void setup() {
    ....
    pinMode(switchPin1, OUTPUT);
    digitalWrite(switchPin1, HIGH);
    ....
}


71205: <p>I have a webserver configured on my esp8266 with is set to fire off electrical relay0 on my 8 port relay board.
The device initializes relay0 perfectly and without errors.
But when I configure the second relay1, i get no response from my second url.</p>
<pre><code>//note, when you write to low, you turn the switchport on. It's backwards for some reason
#include &lt;ESP8266WiFi.h&gt;
#define statusLed 2   // built-in led for the ESP8266-12

const char* ssid = &quot;myssid&quot;;
const char* password = &quot;mypass&quot;;
 
int switchPin0 = 16;
int switchPin1 = 5;
int switch0;
int switch1;

WiFiServer server(80);
 
void setup() {
  Serial.begin(115200);
  delay(10);
 
  pinMode(statusLed, OUTPUT);
  pinMode(switchPin0, OUTPUT);
  digitalWrite(switchPin0, HIGH);

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print(&quot;Connecting to &quot;);
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(&quot;.&quot;);
  }
  digitalWrite(statusLed, HIGH);
  Serial.println(&quot;&quot;);
  Serial.println(&quot;WiFi connected&quot;);
 
  // Start the server
  server.begin();
  Serial.println(&quot;Server started&quot;);
 
  // Print the IP address
  Serial.print(&quot;Use this URL : &quot;);
  Serial.print(&quot;http://&quot;);
  Serial.print(WiFi.localIP());
  Serial.println(&quot;/&quot;);
 
}
 
void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
 
  // Wait until the client sends some data
  Serial.println(&quot;new client&quot;);
  while(!client.available()){
    delay(1);
  }
 
  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);

  client.flush();

  // Match the request
 
  int value = HIGH;
  if (request.indexOf(&quot;/SWITCH=0&quot;) != -1){
    digitalWrite(switchPin0, LOW);
    digitalWrite(statusLed, LOW);   // blink led
    delay(1);
    digitalWrite(statusLed, HIGH);
    //set water pump time here
    delay(8000);
    digitalWrite(switchPin0, HIGH);
    value = HIGH;
    ++switch0;
  } else if (request.indexOf(&quot;/SWITCH=1&quot;) != -1){
    digitalWrite(switchPin1, LOW);
    digitalWrite(statusLed, LOW);   // blink led
    delay(1);
    digitalWrite(statusLed, HIGH);
    //set water pump time here
    delay(8000);
    digitalWrite(switchPin1, HIGH);
    value = HIGH;
    ++switch1;
  } else {

    }
 
  // Return the response
  client.println(&quot;HTTP/1.1 200 OK&quot;);
  client.println(&quot;Content-Type: text/html&quot;);
  client.println(&quot;&quot;); //  do not forget this one
  client.println(&quot;&lt;!DOCTYPE HTML&gt;&quot;);
  client.println(&quot;&lt;html&gt;&quot;);
 
  client.print(&quot;Switch pin is now: &quot;);
 
  if(value == HIGH) {
    client.print(&quot;Off&quot;);  
  } else {
    client.print(&quot;On&quot;);
  }
  client.println(&quot;&lt;br&gt;&lt;br&gt;&quot;);
  client.println(&quot;Switch 0&quot;);
  client.println(&quot;Click &lt;a href=\&quot;/SWITCH=0\&quot;&gt;here&lt;/a&gt;  to send a measured amount&lt;br&gt;&quot;);
  client.println(&quot;Number of times plant 0 has been fed is &quot;);
  client.println(switch0);
  client.println(&quot;&lt;br&gt;&lt;br&gt;&quot;);
  client.println(&quot;Switch 1&quot;);
  client.println(&quot;Click &lt;a href=\&quot;/SWITCH=1\&quot;&gt;here&lt;/a&gt;  to send a measured amount&lt;br&gt;&quot;);
  client.println(&quot;Number of times plant 1 has been fed is &quot;);
  client.println(switch1);
  client.println(&quot;&lt;/html&gt;&quot;);
 
  delay(1);
  Serial.println(&quot;Client disconnected&quot;);
  Serial.println(&quot;&quot;);
  digitalWrite(statusLed, LOW);   // blink led
  delay(1);
  digitalWrite(statusLed, HIGH);
 
}
</code></pre>
<p>my counter will update, but the relay pin never fires for relay1. relay0 works fine. I can swap the ports and then the second relay will work and not the first. I just can't manage both.</p>
<p>How do I get a second (or more) relay ports to initialize via webpage?</p>
 62523: <p>It looks like you forgot to initialize <code>switchPin1</code> to be an output.</p>
<p>Add the following to your <code>setup()</code> (for example, right after the corresponding initialization commands for <code>switchPin0</code>):</p>
<pre><code>void setup() {
    ....
    pinMode(switchPin1, OUTPUT);
    digitalWrite(switchPin1, HIGH);
    ....
}
</code></pre>
