Arduino Project


General News

I started this Arduino project with the objective to be able to login to an ethernet server on my home network and turn a computers power on and off. I have an old server that I seldom need and I don't want to leave running all of the time but when I do need it I want to be able to remotely power it up. I also run this website from a server on my network and it occasionally hangs and needs to be powered down and back up. This project, when complete will allow me to control up to four devices. I did my testing with a relay board but I will switch to solid state switches to do the actual power switching. Once I have completed the packaging I will post another article documenting what I did.

Below is the Arduino/Webduino code.

I tested it in Chrome and it worked fine. When I tried it in IE9 I had an issue where IE set the Document Mode to quirks. When I set it to IE9 standards it worked fine.

I was also able to test it on my Android phone using the web browser

Please leave a Facebook comment at the bottom of this article.


//*****************************************************
#define WEBDUINO_AUTH_REALM "Authentication Required"

#include "SPI.h"
#include "Ethernet.h"
#include "WebServer.h"

static uint8_t mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
static uint8_t ip[] = { 
  192, 168, 1, 111 };
#define PREFIX "/control"
WebServer webserver(PREFIX, 85);

// Set the number of relays you want to be active.
// Only active relays show on the web page
// Inactive = 1  Active = 0
int Relay1active = 0; 
int Relay2active = 0;  
int Relay3active = 0;   
int Relay4active = 0;   

// Set the power up state of each relay  
//OFF = 1  ON = 0
int Relay1state = 0; 
int Relay2state = 0;  
int Relay3state = 0;   
int Relay4state = 1;   

//Button Labels
String R1text = "Server Power";
String R2text = "Relay2";
String R3text = "PC Power";
String R4text = "Garage Door";

void defaultCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{


   /* username = admin
   * password = admin
   * "YWRtaW46YWRtaW4=" is the Base64 representation of "admin:admin" */
    if (server.checkCredentials("YWRtaW46YWRtaW4="))
  {


  //**************************
  // process post data here
  //**************************
  if (type == WebServer::POST)
  {
    bool repeat;
    char name[16], value[16];



    do
    {
      repeat = server.readPOSTparam(name, 16, value, 16);

      if (strcmp(name, "Relay1") == 0)
      {
        if (strcmp(value, "0") == 0)
        {
          digitalWrite(2, HIGH);    
        }
        else if (strcmp(value, "1") == 0)
        {
          digitalWrite(2, LOW);    
        }
      }

      if (strcmp(name, "Relay2") == 0)
      {
        if (strcmp(value, "0") == 0)
        {
          digitalWrite(3, HIGH);    
        }
        else if (strcmp(value, "1") == 0)
        {
          digitalWrite(3, LOW);    
        }
      }

      if (strcmp(name, "Relay3") == 0)
      {
        if (strcmp(value, "0") == 0)
        {
          digitalWrite(4, HIGH);    
        }
        else if (strcmp(value, "1") == 0)
        {
          digitalWrite(4, LOW);    
        }
      }

      if (strcmp(name, "Relay4") == 0)
      {
        if (strcmp(value, "0") == 0)
        {
          digitalWrite(5, HIGH);    
        }
        else if (strcmp(value, "1") == 0)
        {
          digitalWrite(5, LOW);    
        }
      }
    } 
    
    while (repeat);

    server.httpSeeOther(PREFIX);
    return;
  }


  server.httpSuccess();



  if (type == WebServer::GET)
  {

    P(messagestart) = 
      "<!DOCTYPE HTML><html><head><title>Power Control Page</title>"
      "<body>"
      "<h1>Power Control</h1>"
      "<form action='/control' method='POST'>";

    P(messageend) = 
      "<p><a href='/control/logout.html'>LOGOUT</a></p>"    
      "</form></body></html>";

    server.printP(messagestart); 

    if (Relay1active == 0)
    {

      if (digitalRead(2) == 0){  
        server.print("<p><button name='Relay1' style='background-color:#088A08; color:#FFFFFF;' value='0'>");
        server.print(R1text);
        server.print(" - is On</button></p>");      
      }
      else{  
        server.print("<p><button name='Relay1' style='background-color:#CC0000; color:#FFFFFF;' value='1'>");
        server.print(R1text);
        server.print("- is Off</button></p>");
      }
    }


    if (Relay2active == 0)
    {
      if (digitalRead(3) == 0){  
        server.print("<p><button name='Relay2' style='background-color:#088A08; color:#FFFFFF;' value='0'>");
        server.print(R2text);
        server.print(" - is On</button></p>");      
      }
      else{  
        server.print("<p><button name='Relay2' style='background-color:#CC0000; color:#FFFFFF;' value='1'>");
        server.print(R2text);
        server.print("- is Off</button></p>");
      }    
    }
    if (Relay3active == 0)
    {
      if (digitalRead(4) == 0){  
        server.print("<p><button name='Relay3' style='background-color:#088A08; color:#FFFFFF;' value='0'>");
        server.print(R3text);
        server.print(" - is On</button></p>");      
      }
      else{  
        server.print("<p><button name='Relay3' style='background-color:#CC0000; color:#FFFFFF;' value='1'>");
        server.print(R3text);
        server.print("- is Off</button></p>");
      }    
    }
    if (Relay4active == 0)
    {
      if (digitalRead(5) == 0){  
        server.print("<p><button name='Relay4' style='background-color:#088A08; color:#FFFFFF;' value='0'>");
        server.print(R4text);
        server.print(" - is On</button></p>");      
      }
      else{  
        server.print("<p><button name='Relay4' style='background-color:#CC0000; color:#FFFFFF;' value='1'>");
        server.print(R4text);
        server.print("- is Off</button></p>");
      }    
    }

    server.printP(messageend);     
  }    
    
  }
  else
  {

    server.httpUnauthorized();
  } 

}

void logoutCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{

  server.httpUnauthorized(); 

  P(logoutMsg) = "<h1>You have been logged out!</h1> <p>Goodbye</p>";

  server.printP(logoutMsg);


}


void setup()
{




  if (Relay1active == 0){
    pinMode(2, OUTPUT); //Set pin as output 
    if (Relay1state == 0){
      digitalWrite(2, LOW);  
    }
    else{
      digitalWrite(2, HIGH);    
    }  
  }

  if (Relay2active == 0){  
    pinMode(3, OUTPUT); //Set pin as output
    if (Relay2state == 0){
      digitalWrite(3, LOW);  
    }
    else{
      digitalWrite(3, HIGH);    
    }
  }  

  if (Relay3active == 0){  
    pinMode(4, OUTPUT); //Set pin as output 
    if (Relay3state == 0){
      digitalWrite(4, LOW);  
    }
    else{
      digitalWrite(4, HIGH);    
    }  
  }

  if (Relay4active == 0){   
    pinMode(5, OUTPUT); //Set pin as output
    if (Relay4state == 0){
      digitalWrite(5, LOW);  
    }
    else{
      digitalWrite(5, HIGH);    
    }  
  }

  Ethernet.begin(mac, ip);
  webserver.setDefaultCommand(&defaultCmd);
  webserver.addCommand("index.html", &defaultCmd);
  webserver.addCommand("logout.html", &logoutCmd);
  webserver.begin();

}

void loop()
{

  webserver.processConnection();

}
//*****************************************************
  • Currently 0.00/5
Rating: 0.00/5 (0 votes cast)

Another Pizza Rip


General News
The spouse picked up a World Table brand pizza based on the photo on the box. As you may have guessed the actual pizza had much to be desired. See the photos below. Here is the box Here is the cooked pizza.
  • Currently 0.00/5
Rating: 0.00/5 (0 votes cast)

WARNING!


General News
Police are warning all men who frequent clubs, parties and local pubs to be alert and stay cautious when offered a drink from any woman.
A date rape drug on the market called Beer is used by many females to target unsuspecting men.
The drug is generally found in liquid form and is now available almost anywhere. It comes in bottles, cans, from taps and in large kegs.

Beer is used by female sexual predators at parties and bars to persuade their male victims to go home and have sex with them. Typically, a woman needs only to persuade a guy to consume a few units of Beer and then simply ask him home for no strings attached sex. Men are rendered helpless against this approach.

After several Beers, men will often succumb to desires to perform sexual acts on horrific looking women to whom they would never normally be attracted. After drinking Beer men often awaken with only hazy memories of exactly what happened to them the night before, often with just a vague feeling that “something bad occurred.

At other times these unfortunate men are swindled out of their lifes savings, in a familiar scam known as a relationship. It has been reported that in extreme cases, the female may even be shrewd enough to entrap the unsuspecting male into a longer term form of servitude and punishment referred to as marriage.
Apparently, men are much more susceptible to this scam after Beer is administered and sex is offered by the predatory females.

Please! Forward this warning to every male you know. If you fall victim to this insidious Beer and the predatory women administering it, there are male support groups with venues in every town where you can discuss the details of your shocking encounter in an open and frank manner with similarly affected, like-minded guys.
  • Currently 0.00/5
Rating: 0.00/5 (0 votes cast)