Remote power and reboot with Arduino

I have a computer in a condo that I use for work very often. The condo is about an hour from my house, so it’s not easy to go there in person on an unplanned occasion. This is the computer that I blogged about using RDP. Recently the computer was running an HFSS simulation and seems to have crashed. I am not actually sure what is wrong with it. Additionally, I have a local router that communicates with my NAS drive. That also went offline. I need a way to remotely reset the PC and restart the router.

I found an Arduino program that interfaces with Ethernet to activate relays. I wrote a program to momentarily activate one relay and turn the other one on and off. I will operate my router through the on-off relay and wire my computer reset switch to the other relay. I will be able to remotely reboot the computer and the router as I would in person.

Since as I blogged about, through Sonic I can forward a port, I will put the device on port 8080. That way I can keep running my web server and also remotely operate this device.

The Arduino with Ethernet is very similar to my last blog. The code is different because this one allows remotely affecting ports on the Arduino. Once I get it running I will add screen shots of the web page and take pictures of the device.

Here is a stock picture of an Arduino with Ethernet.

Here is the Arduino code. I don’t know why WordPress does weird stuff to pasted text. Sorry about that.

/*
Web Server
A simple web server
Circuit:

  • Ethernet shield attached to pins 10, 11, 12, 13
    */
    //—————————————————————————————————-

#include <SPI.h>

#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0x4C, 0xB1 };

// The IP address will be dependent on your local network:
// assign an IP address for the controller:

IPAddress ip(10,0,0,196);
IPAddress gateway(10,0,0,1);
IPAddress subnet(255, 255, 255, 0);

// Initialize the Ethernet server library with the port you want to use.
EthernetServer server(80);
String readString;
//——————————————————————————————————-
//————————————————-
// Any extra codes for Declaration :

// Declare Pin 8 as an LED because thats what we will be connecting the LED to.You could use any other pin and would then have to change the pin number.
int led = 8;
int led2 = 7;

//————————————————-
//——————————————————————————————————-
void setup()
{
//————————————————-

// Extra Set up code:
pinMode(led, OUTPUT); //pin selected to control
pinMode(led2,OUTPUT);

//————————————————-
//——————————————————————————————————-
//enable serial data print
Serial.begin(9600);

//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.print(“Server is at “);
Serial.println(Ethernet.localIP());
Serial.println(“LED Controller Test 1.0”);
}
//——————————————————————————————————-
//——————————————————————————————————-

void loop()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client)

{
Serial.println(“new client”);

while (client.connected())
{
  if (client.available())

  {
    char c = client.read();

    //read char by char HTTP request
    if (readString.length() < 100)

    {

      //store characters to string
      readString += c;
      //Serial.print(c);


      Serial.write(c);
      // if you've gotten to the end of the line (received a newline
      // character) and the line is blank, the http request has ended,
      // so you can send a reply
      //if HTTP request has ended
      if (c == '\n') {
        Serial.println(readString); //print to serial monitor for debuging

//——————————————————————————————————–
// Needed to Display Site:
client.println(“HTTP/1.1 200 OK”); //send new page
client.println(“Content-Type: text/html”);
client.println();
client.println(“”);
client.println(“”);

//——————————————————————————————————–
//————————————————-

// what is being Displayed :

        client.println("<TITLE>Home Automation</TITLE>");
         client.println("<center>");
        client.println("</HEAD>");
        client.println("<BODY>");
        client.println("<H1>Home Automation</H1>");
        client.println("<hr />");
        client.println("<center>");

        client.println("<a href=\"/?lighton1\"\">Turn On 1</a>");
        client.println("<br />");
        client.println("<br />");
        client.println("<a href=\"/?lightoff1\"\">Turn Off 1</a><br />");   
        client.println("<br />");
        client.println("<br />");
        client.println("<a href=\"/?pulse2\"\">Pulse 2</a>"); 

        client.println("</BODY>");
        client.println("</HTML>");

        delay(1);
        //stopping client
        client.stop();

        //-------------------------------------------------
        // Code which needs to be Implemented:
        if(readString.indexOf("?lighton1") >0)//checks for on
        {
          digitalWrite(8, HIGH);    // set pin 8 high
          Serial.println("Led On");
        }
        else if(readString.indexOf("?lightoff1") >0)//checks for off
          {
            digitalWrite(8, LOW);    // set pin 8 low
            Serial.println("Led Off");
          }

        else if(readString.indexOf("?pulse2") >0)//checks for off
          {
            digitalWrite(7, HIGH);    // set pin 8 low
            delay(500);
            digitalWrite(7,LOW);
            Serial.println("Pulse 2");
          }

        //clearing string for next read
        readString="";

        // give the web browser time to receive the data
        delay(1);
        // close the connection:
        client.stop();
        Serial.println("client disonnected");

      }
    }
  }
}

}
}

Leave a comment