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