Arduino Web Server and Relay Module I am working on a web server project for work. I have a web server setup with an Arduino Meg2560 with Ethernet. I also have a 16 relay board connected to Ethernet with its own IP. I wanted to see if there is a way I can make calls to the relay board via IP from the Arduino Webserver. For example Relay 1 on the relay board can be turned on by typing 192.168.1.4/30000/00 but this opens the web GUI on the board. I need to do the same thing but without opening the webpage or web GUI.


    #include &lt;SPI.h&gt;
    #include &lt;Ethernet.h&gt;

    // MAC address from Ethernet shield sticker under board
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    IPAddress ip(192, 168, 1, 177); // IP address
    EthernetServer server(80);  // Server Port 80

    void setup()
    {
      Ethernet.begin(mac, ip);  
      server.begin();           
    }

    void loop()
{
EthernetClient client = server.available();  // try to get client

if (client) {  // got client?
    boolean currentLineIsBlank = true;
    while (client.connected()) {
        if (client.available()) {   // client data available to read
            char c = client.read(); // read 1 byte (character) from client
            // last line of client request is blank and ends with \n
            // respond to client only after last line received
            if (c == '\n' &amp;&amp; currentLineIsBlank) {
                // send a standard http response header
                client.println("HTTP/1.1 200 OK");
                client.println("Content-Type: text/html");
                client.println("Connection: close");
                client.println();
                // send web page
                client.println("&lt;!DOCTYPE html&gt;");
                client.println("&lt;html&gt;");
                client.println("&lt;head&gt;");
                client.println("&lt;title&gt;Arduino Web Page&lt;/title&gt;");
                client.println("&lt;/head&gt;");
                client.println("&lt;body&gt;");
                client.println("&lt;h1&gt;Hello from Arduino!&lt;/h1&gt;");
                client.println("&lt;p&gt;A web page from the Arduino server&lt;/p&gt;");
                client.println("&lt;/body&gt;");
                client.println("&lt;/html&gt;");
                break;
            }
            // every line of text received from the client ends with \r\n
            if (c == '\n') {
                // last character on line of received text
                // starting new line with next character read
                currentLineIsBlank = true;
            } 
            else if (c != '\r') {
                // a text character was received from client
                currentLineIsBlank = false;
            }
        } // end if (client.available())
    } // end while (client.connected())
    delay(1);      // give the web browser time to receive the data
    client.stop(); // close the connection
} // end if (client)


}
Documentation on the controller you are using is pretty scant, but it looks like you just need to make a GET request to the URI corresponding to the action you need to take.


  http://192.168.1.4/30000/00 : Relay-01 OFF
  
  http://192.168.1.4/30000/01 : Relay-01 ON
  
  http://192.168.1.4/30000/02 : Relay-02 OFF
  
  http://192.168.1.4/30000/03 : Relay-02 ON
  
  http://192.168.1.4/30000/04 : Relay-03 OFF
  
  http://192.168.1.4/30000/05 : Relay-03 ON
  
  …
  
  http://192.168.1.4/30000/14 : Relay-8 OFF
  
  http://192.168.1.4/30000/15 : Relay-8 ON
  
  http://192.168.1.4/30000/41 : Enter
  
  http://192.168.1.4/30000/40 : Exit
  
  http://192.168.1.4/30000/42 : Next Page
  
  http://192.168.1.4/30000/43 : Next Page


For example If I wanted to turn off relay 3, I would simple make a GET request to http://192.168.1.4/30000/04 and close the connection. Example code:

IPAddress server(192,168,1,4);
EthernetClient client;
client.connect(server, 80);
client.println("GET /30000/04 HTTP/1.1");
client.println("Connection: close");
client.println();
client.stop();