Was this code helpful for you?

Yes
1
100%
No
0
No votes
 
Total votes : 1

Using the Arduino Ethernet to reset hardware using SSR

by dimbeault on Tue May 07, 2013 10:43 pm

Hi everyone,

I have a fun little code that I'm sharing with you. My internet router sometime loses it's cellular connection. I placed my modem at the best place to receive the cellular signal, in the roof of my house. So when I need to reset it, I need to go up there, disconnect and ... well you know the rest. (dont tell me about software reset, it does'nt work.)

So this Arduino Ethernet code control a SSR (solid state relay) on pin 9 (I used that one since it has the onboard LED). So all I have to do is to load the web page of my Arduino and click the reset button. If you use this code for an other hardware, please note that after a reset, I dont send the webpage content, since I reset the router, all communication are lost.

You need to put this file in the SD card first (the html page content) under the name "RESET.TXT"

Code: Select all | TOGGLE FULL SIZE
HTTP/1.1 200 OK
Content-Type: text/html
Connection: close

<!DOCTYPE html>
<html>
<head>
<title>Hardware Reset</title>
</head>
<body>
<h1>Arduino Ethernet Hardware Reset</h1>
<p>Click to reset your hardware</p>
<form method="get">
<input type="hidden" name="action" value="reset">
<input type="button" name="rst" value="Reset" title="Click to reset" onclick="submit();" />
</form>
</body>
</html>


and the Arduino Ethernet code :

Code: Select all | TOGGLE FULL SIZE
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>

byte mac[] = { your_mac_address };
IPAddress ip( your_ip_adress);

EthernetServer server(80);

String HTTP_req;

File myFile;

void setup()
{
  Serial.begin(9600);
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.println(Ethernet.localIP());
  pinMode( 9, OUTPUT);
  SD.begin(4);
  digitalWrite(9, HIGH);
}

void loop()
{
  EthernetClient client = server.available();

  if (client) {
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        HTTP_req += c;
        if (c == '\n') {
          if (HTTP_req.indexOf("GET") > -1) {

            if(HTTP_req.indexOf("action=reset") > -1) {
              digitalWrite(9, LOW);
              delay(5000);
              digitalWrite(9, HIGH);
              HTTP_req = "";
              break;
            }
            else
            {
              myFile = SD.open("RESET.TXT");
              if (myFile) {
                while (myFile.available()) {
                  client.write(myFile.read());
                }
                myFile.close();
              }

              HTTP_req = "";
              break;
            }
          }
        }
      }
    }
    delay(1);
    client.stop();
  }
}
User avatar
dimbeault
 
Posts: 51
Joined: Sun Dec 30, 2012 6:15 pm
Location: Franquelin, Québec, Canada