Home Automation error message

Hi folks, i've been working on a simple home automation project using a slightly modified pre-existing code for an ethernet/RF transmitter set up.

I can connect to the shield it seems to do what it should, except for two of the On/Off buttons as seen when connected to through a web browser. In the below code, The buttons labeled - On Off - Boekenkast - & - On Off - Voordeur - just return a web page saying EPIC FAIL when pressed. I can't figure out why. All the code seems identical (I may have missed something).

Thanks in advance.

FTL

#include <RemoteTransmitter.h>
#include <Ethernet.h>
#include <SPI.h>
#include <WebServer.h>

//Connections to the Arduino board
const int ledPin =  9; 
const int transmitterPin = 8;

//Duration of a RF command
const unsigned int period = 326;

//RF codes for switching the lights
const unsigned long aOn = 175682; //Middenlamp
const unsigned long aOff = 175686;
const unsigned long bOn = 176654; //Hoeklamp
const unsigned long bOff = 176658;
const unsigned long cOn = 176978; //Rode lamp
const unsigned long cOff = 176982;
const unsigned long dOn = 177086; //Boekenkast
const unsigned long dOff = 177090;
const unsigned long eOn = 57584; //Voordeur
const unsigned long eOff = 57588;

//Bijhouden van de status van de lampen
boolean aIsOn = false;
boolean bIsOn = false;
boolean cIsOn = false;
boolean dIsOn = false;
boolean eIsOn = false;


//Stukjes output
P(message1) = 
      "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">"
      "<html><head>"
      "<title>Lights</title>"
      "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"http://rogier.nu/l/library/download/554?format=save_to_disk&ext=.css\" />"
      "<meta name=\"viewport\" content=\"width=320\">"
      "</head>"
      "<body><h1>Zendelingen Lights</h1>"
      "<p>
<a class='positive' href='/allesOn'>On</a> "
      "<a class='negative' href='/allesOff'>Off</a> - All lights"
      "<p>

<a class='";
P(message2) = "' href='/aOn'>On</a> <a class='";
P(message3) =
      "' href='/aOff'>Off</a> - Sputnik Lamp</p>"
      "<p>

<a class='";

P(message4) = "' href='/bOn'>On</a> <a class='";
P(message5) = 
      "' href='/bOff'>Off</a> - Hoek-lamp</p>"
      "<p>

<a class='";

P(message6) = "' href='/dOn'>On</a> <a class='";
P(message7) = 
      "' href='/dOff'>Off</a> - Boekenkast</p>"
      "<p>

<a class='";

P(message8) = "' href='/eOn'>On</a> <a class='";
P(message9) = 
      "' href='/eOff'>Off</a> - Voordeur</p>"
      "<p>

<a class='";


P(message10) = "' href='/cOn'>On</a> <a class='";
P(message11) = 
      "' href='/cOff'>Off</a>   - Rode lamp</p>";


P(messageEnd) = 
      "</p></body></html>";

P(positive) = "positive";
P(positiveOn) = "positive-on";
P(negative) = "negative";
P(negativeOn) = "negative-on";

//Webserver settings
static uint8_t mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xAD, 0xFA };
static uint8_t ip[] = { 192, 168, 0, 201 };
#define PREFIX ""
WebServer webserver(PREFIX, 80);

long previousResetCheckMillis = 0;
long intervalResetCheck = 1800000; //half uur

2nd half of the code (sorry, the forum said i had too many characters!!).

FTL

//--------------------------------------------------------------------------------------------------------------

/* This command is set as the default command for the server.  It
 * handles both GET and POST requests.  For a GET, it returns a simple
 * page with some buttons. */
void defaultCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  if (type == WebServer::POST)
  {
    Serial.println("ToggleLightCMD");
   
   
    bool repeat;
    char name[16], value[16];
    do
    {
      repeat = server.readPOSTparam(name, 16, value, 16);
      Serial.print("Name: ");
      Serial.println(name);
      Serial.print("Value: ");
      Serial.println(value);
      
      if (strcmp(name, "command") == 0)
      {
        switchLights(value); 
      }
    } while (repeat);
    
    server.httpSeeOther("/");
    return;
  }

  /* for a GET or HEAD, send the standard "it's all OK headers" */
  server.httpSuccess();

  /* we don't output the body for a HEAD request */
  if (type == WebServer::GET)
  { 
      server.printP(message1);
      server.printP(aIsOn ? positiveOn : positive); 
      server.printP(message2);
      server.printP(aIsOn ? negative : negativeOn); 
      server.printP(message3);
      server.printP(bIsOn ? positiveOn : positive); 
      server.printP(message4);
      server.printP(bIsOn ? negative : negativeOn); 
      server.printP(message5);
      
      server.printP(dIsOn ? positiveOn : positive); 
      server.printP(message6);
      server.printP(dIsOn ? negative : negativeOn); 
      server.printP(message7);
      
      server.printP(eIsOn ? positiveOn : positive); 
      server.printP(message8);
      server.printP(eIsOn ? negative : negativeOn); 
      server.printP(message9);
      
      server.printP(cIsOn ? positiveOn : positive); 
      server.printP(message10);
      server.printP(cIsOn ? negative : negativeOn); 
      server.printP(message11);
      server.printP(messageEnd);
  }
}

void allOnCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  switchLights("aOn"); 
  switchLights("bOn"); 
  switchLights("cOn"); 
  switchLights("dOn"); 
  switchLights("eOn"); 
  server.httpSeeOther("/");
  return;
}

void allOffCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  switchLights("aOff"); 
  switchLights("bOff"); 
  switchLights("cOff"); 
  switchLights("dOff"); 
  switchLights("eOff"); 
  server.httpSeeOther("/");
  return;
}


void aOnCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  switchLights("aOn"); 
  server.httpSeeOther("/");
  return;
}

void aOffCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  switchLights("aOff"); 
  server.httpSeeOther("/");
  return;
}

void bOnCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  switchLights("bOn"); 
  server.httpSeeOther("/");
  return;
}

void bOffCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  switchLights("bOff"); 
  server.httpSeeOther("/");
  return;
}

void cOnCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  switchLights("cOn"); 
  server.httpSeeOther("/");
  return;
}

void cOffCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  switchLights("cOff"); 
  server.httpSeeOther("/");
  return;
}

void dOnCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  switchLights("dOn"); 
  server.httpSeeOther("/");
  return;
}

void dOffCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  switchLights("dOff"); 
  server.httpSeeOther("/");
  return;
}

void eOnCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  switchLights("eOn"); 
  server.httpSeeOther("/");
  return;
}

void eOffCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  switchLights("eOff"); 
  server.httpSeeOther("/");
  return;
}



void switchLights(String value) {
  if (value == "aOn") { sendSwitchSignal(aOn); aIsOn = true; }
  if (value == "aOff") { sendSwitchSignal(aOff); aIsOn = false; }
  if (value == "bOn") { sendSwitchSignal(bOn); bIsOn = true; }
  if (value == "bOff") { sendSwitchSignal(bOff); bIsOn = false; }
  if (value == "cOn") { sendSwitchSignal(cOn); cIsOn = true; }
  if (value == "cOff") { sendSwitchSignal(cOff); cIsOn = false; }
  if (value == "dOn") { sendSwitchSignal(dOn); dIsOn = true; }
  if (value == "dOff") { sendSwitchSignal(dOff); dIsOn = false; }
  if (value == "eOn") { sendSwitchSignal(eOn); eIsOn = true; }
  if (value == "eOff") { sendSwitchSignal(eOff); eIsOn = false; }
}

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);  
  
  Ethernet.begin(mac, ip);
  webserver.setDefaultCommand(&defaultCmd);
  
  webserver.addCommand("allesOn", &allOnCmd);
  webserver.addCommand("allesOff", &allOffCmd);
  webserver.addCommand("aOn", &aOnCmd);
  webserver.addCommand("aOff", &aOffCmd);
  webserver.addCommand("bOn", &bOnCmd);
  webserver.addCommand("bOff", &bOffCmd);
  webserver.addCommand("cOn", &cOnCmd);
  webserver.addCommand("cOff", &cOffCmd);
  webserver.addCommand("dOn", &dOnCmd);
  webserver.addCommand("dOff", &dOffCmd);
  webserver.addCommand("eOn", &eOnCmd);
  webserver.addCommand("eOff", &eOffCmd);
  webserver.begin();
}

void loop() {
  //process incoming connections one at a time forever
  webserver.processConnection();
  
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousResetCheckMillis > intervalResetCheck) {
    previousResetCheckMillis = currentMillis;
    resetTheLights();
  }
}


void resetTheLights()
{
  if(aIsOn == false) { switchLights("aOff"); }
  if(bIsOn == false) { switchLights("bOff"); }
  if(cIsOn == false) { switchLights("cOff"); }
  if(dIsOn == false) { switchLights("dOff"); }
  if(eIsOn == false) { switchLights("eOff"); }
}

void sendSwitchSignal(unsigned long actionCode) {
  digitalWrite(ledPin, HIGH);
  
  //Disable the receiver; otherwise it might pick up the retransmit as well.
//  RemoteReceiver::disable();
  
  //Need interrupts for delay
  interrupts();
  
  unsigned long code;
  
  //Copy the received code. 
  code = actionCode & 0xFFFFF; //truncate to 20 bits for show; receivedCode is never more than 20 bits..
  
  //Add the period duration to the code. Range: [0..511] (9 bit)
  code |= (unsigned long)period << 23;
  
  //Add the number of repeats to the code. Range: [0..7] (3 bit). The actual number of repeats will be 2^(repeats), 
  //in this case 8
  code |= 3L << 20;
  
//  RemoteSwitch::sendTelegram(code,transmitterPin);
  RemoteTransmitter::sendCode(transmitterPin, actionCode, period, 3);
  
//  RemoteReceiver::enable();
  digitalWrite(ledPin, LOW);
}

When the web page is served up, what does the source look like? In the browser, right click and pick the option to view the page source. Copy and paste that code here.

Will do when i'm home. It only works on my home network right now.

FTL

Page source -

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"><html><head><title>Lights</title><link rel="stylesheet" type="text/css" media="screen" href="http://rogier.nu/l/library/download/554?format=save_to_disk&ext=.css" /><meta name="viewport" content="width=320"></head><body><h1>Zendelingen Lights</h1><p>
<a class='positive' href='/allesOn'>On</a> <a class='negative' href='/allesOff'>Off</a> - All lights<p>

<a class='positive-on' href='/aOn'>On</a> <a class='negative' href='/aOff'>Off</a> - Sputnik Lamp</p><p>

<a class='positive-on' href='/bOn'>On</a> <a class='negative' href='/bOff'>Off</a> - Hoek-lamp</p><p>

<a class='positive-on' href='/dOn'>On</a> <a class='negative' href='/dOff'>Off</a> - Boekenkast</p><p>

<a class='positive-on' href='/eOn'>On</a> <a class='negative' href='/eOff'>Off</a> - Voordeur</p><p>

<a class='positive-on' href='/cOn'>On</a> <a class='negative' href='/cOff'>Off</a>   - Rode lamp</p></p></body></html>

Spread out a little, so as to be readable:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html>
<head>
<title>Lights</title>
<link rel="stylesheet" type="text/css" media="screen" href="http://rogier.nu/l/library/download/554?format=save_to_disk&ext=.css" />
<meta name="viewport" content="width=320">
</head>
<body>
<h1>Zendelingen Lights</h1>
<p>


<a class='positive' href='/allesOn'>On</a>
<a class='negative' href='/allesOff'>Off</a> - All lights
<p>




<a class='positive-on' href='/aOn'>On</a>
<a class='negative' href='/aOff'>Off</a> - Sputnik Lamp
</p>
<p>




<a class='positive-on' href='/bOn'>On</a>
<a class='negative' href='/bOff'>Off</a> - Hoek-lamp
</p>
<p>




<a class='positive-on' href='/dOn'>On</a>
<a class='negative' href='/dOff'>Off</a> - Boekenkast
</p>
<p>




<a class='positive-on' href='/eOn'>On</a>
<a class='negative' href='/eOff'>Off</a> - Voordeur
</p>
<p>




<a class='positive-on' href='/cOn'>On</a>
<a class='negative' href='/cOff'>Off</a>   - Rode lamp
</p>
</p>
</body>
</html>

You have different classes for the On buttons. I don't see that the

tags are useful. from what I've seen in web pages, that tag does not need to be closed.

I don't see that these issues are relevant to the problem, but, I thought I'd point them out.

Where does this "EPIC FAIL" message appear?

Ok. I don't really understand HTML, like i say, this is re-existing code. So anyway, i'm not totally sure what you mean by different classes. But logically unless this is the case for 'boekenkast' and 'voorduer' but not the rest.... it shouldn't be the issue.

As i modified the code a bit i was worried that is was something i did that caused this. But after going back and uploading the origional code the problem persists.

The 'Epic Fail' turns up at the top left of the webpage. The coding works by sending a ip address + the RF code command when you click a button. For example http://192.168.0.201/eOff. Normally, when all is well, it just returns to the ip address of the ethernet shield. On these two buttons however it comes up with this 'epic fail'.

I can post screenshots?

I can post screenshots?

You can. Does anything appear in the browser when you hover over a button?

So anyway, i'm not totally sure what you mean by different classes.

On
On
On
On
On
On
positive and positive-on look like different classes to me.

Ah, i think i can explain that. The... On... is a button that triggers all at once i.e. all RF codes with one button. Where as... On... for example is just for one button/switch/RF code.

Screen shots to come.

FTL

The class defines a style from the style sheet. It has not affect on the behavior of the button. Are all three styles defined in the style sheet?

Frankly, I'd ditch the style sheet altogether. Design your form so that it is not needed.

Not using a style sheet means less data to send (as does not using

and the almost certainly not needed

tags).

Screenshots attached of -

Normal screen (as seen when navigated to ethernet shield's IP)

Hover button (as seen when cursor hovers over one of the problem buttons)

Fail (epic fail screen)

PaulS:
The class defines a style from the style sheet. It has not affect on the behavior of the button. Are all three styles defined in the style sheet?

Frankly, I'd ditch the style sheet altogether. Design your form so that it is not needed.

Not using a style sheet means less data to send (as does not using

and the almost certainly not needed

tags).

That is a little beyond my skills i'm afraid.

:?

FTL

Hmm. I'm still quite perplexed. Do you think it could be something to do with the order of the code for each ?value? being different in different places. What i mean is Rode lamp is 'cOn' for example. Where as Boekenkast and Voorduer are dOn and cOn respectively and c, d and e appear in different orders in different sections of the code?

Anyone?

FTL

Hello fasterthanlight,

If you receive the message 'EPIC FAIL' while using the webduino library it would indicate to me that the url you are using is not understood by the Arduino server.

I have not fully taken in your code yet, but where this message can originate from is where you add server commands, such as the following,

webserver.addCommand("allesOn", &allOnCmd)

The first parameter "allesON' is the URL tail section and the second parameter is your function to handle the command.
If you either do not have the specific command added to the server list as above or you do not have the function, then you will get the "EPIC FAIL" message.

Hope this helps somewhat.

Paul

I spent a little more time looking at the code you have and the section where you add server commands with their respective functions appear to look ok to me. So, I am also a little perplexed why you would get an 'EPIC FAIL' message.

The following code section;

void eOffCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  switchLights("eOff"); 
  server.httpSeeOther("/");
  return;
}

And after looking at the webduino code to see what server.httpSeeOther() function is about, (line 268 of WebServer.h) it is used with a POST to redirect output to another URL. I do not understand why this command is used in you code.

Looking at my own code I do not use it, but use the following code;

void Cmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  server.httpSuccess();
  .
  .
  . 
  return;
}

server.httpSuccess, as it suggests, sends back the standard http ok headers to your browser.

What you could try to do is to add some serial print commands, say in the code sections like above for those particular lights, to see that the command is at least being run.

For example:

void dOnCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete) {
    server.httpSuccess();
    Serial.print("Ik lees naast de boekenkast - dOn"); 
    switchLights("dOn"); 
    return;
}

This will show whether you are getting to this point in the program.

Paul

I'm afraid i'm a little inexperienced for this but i do apreiciate the help.

All i can say for sure is that when i hit the buttons for any other device except boekenkast and voorduer its is getting through as the lights blink on the shield. This does not happen with B and V, and a web page returns with EPIC FAIL.

FTL