Who's your daddy?

Welcome to The Rude Bastard web site
Tuesday, September 27 2016 @ 07:05 PM CDT

ChatterBlock

Registered user feature


View Printable Version

SaveSandy.org

General NewsMy sister in-law Sandy Phan-Gillis has been detained in China by the China Ministry of State Security since March 19, 2015, and is being investigated on charges of Spying and Stealing State Secrets.
Sandy is not a spy or a thief. Representatives of the Chinese Foreign Ministry have admitted as much. The purpose of this site is to provide information about Sandy and her case, and to help free her from her detention in China. This site is also meant to be a call to action, and suggests steps that you can take to help.

http://www.savesandy.org/
Share
  • Facebook
View Printable Version

Arduino Project

Arduino

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();

}
//*****************************************************
Share
  • Facebook
View Printable Version

Do Not Watch this Video

Movies
Share
  • Facebook
View Printable Version

Chewbacca

Cool

Chewbacca

Share
  • Facebook
View Printable Version

Another Pizza Rip

AngryThe 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.


Share
  • Facebook
First | Previous | 1 234567| Next | Last