I have been working on this program which accepts commands from the web and issues X10 power house commands. Seperately the X10 code works great and seperately the web server code works great. And together they are working until I added coding for all 16 modules. (Was working good with code to decode a few X10 modules).
Most of the code I have gotten off the web. I am using an Uno and the Arduino Ehternet shield. The biggest problem right now is I can't connect from a browser, the Arduino is not sending out the web page. The program is looping through the main loop but the web page is not being sent. It seems to have broken when I added the code for modules 8 - 16.
Could you look at the client code and tell me if you see anything wrong? Thanks.
//program to accept x10 commands from web site using ehternet shield and pl513
// 1/21/13
#include <SPI.h>
#include <Ethernet.h>
#include <x10.h>
#include <x10constants.h>
#define zcPin 2 //moodule pl513 pin 1 goes to Arduino pin 2
#define dataPin 7 //pl513 pin 4 goes to Arduino pin 7 and 10k pullup resistor
byte mac[] = {
0x48, 0xC2, 0xA1, 0xF3, 0x8D, 0xB7 };
byte ip[] = {
192,168,1,66 }; //i am using ip=66, port 8080
// Start the server on port 8080
EthernetServer server(8080);
String readString; //put data read from web here
// set up a new x10 instance:
x10 myHouse = x10(zcPin, dataPin);
void setup(){
Ethernet.begin(mac, ip);
//Ethernet.begin(mac, ip, gateway, gateway, subnet);
server.begin();
Serial.begin(9600);
}
void loop()
{
Serial.println("begin loop");
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
////////////////////////////////////////////
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); // Standard HTTP response
client.println("Content-Type: text/html\n");
//client.println("<html><head><META CONTENT=""15"" HTTP-EQUIV=""Refresh"">\n");
client.println("<HTML>");
client.println("<HEAD>");
client.println("<title>Joe's X10 Remote Control Program</title></head>");
client.println("<body>\n");
client.println("<h1>Joe's X10 Remote Control Program</h1>");
client.println("<h3>Click on device and operation</h3>");
client.println("<a href='/?C1ON'>C1 ON </a>");
client.println("<a href='/?C1OFF'>C1 OFF </a>");
client.println("
");
client.println("<a href='/?C2ON'>C2 ON </a>");
client.println("<a href='/?C2OFF'>C2 OFF </a>");
client.println("
");
client.println("<a href='/?C3ON'>C3 ON </a>");
client.println("<a href='/?C3OFF'>C3 OFF </a>");
client.println("
");
client.println("<a href='/?C4ON'>C4 ON </a>");
client.println("<a href='/?C4OFF'>C4 OFF </a>");
client.println("
");
client.println("<a href='/?C5ON'>C5 ON </a>");
client.println("<a href='/?C5OFF'>C5 OFF </a>");
client.println("
");
client.println("<a href='/?C6ON'>C6 ON </a>");
client.println("<a href='/?C6OFF'>C6 OFF </a>");
client.println("
");
client.println("<a href='/?C7ON'>C7 ON </a>");
client.println("<a href='/?C7OFF'>C7 OFF </a>");
client.println("
");
client.println("<a href='/?C8ON'>C8 ON </a>");
client.println("<a href='/?C8OFF'>C8 OFF </a>");
client.println("
");
client.println("<a href='/?C9ON'>C9 ON </a>");
client.println("<a href='/?C9OFF'>C9 OFF </a>");
client.println("
");
client.println("<a href='/?C10ON'>C10 ON </a>");
client.println("<a href='/?C10OFF'>C10 OFF </a>");
client.println("
");
client.println("<a href='/?C11ON'>C11 ON </a>");
client.println("<a href='/?C11OFF'>C11 OFF </a>");
client.println("
");
client.println("<a href='/?C12ON'>C12 ON </a>");
client.println("<a href='/?C12OFF'>C12 OFF </a>");
client.println("
");
client.println("<a href='/?C13ON'>C13 ON </a>");
client.println("<a href='/?C13OFF'>C13 OFF </a>");
client.println("
");
client.println("<a href='/?C14ON'>C14 ON </a>");
client.println("<a href='/?C14OFF'>C14 OFF </a>");
client.println("
");
client.println("<a href='/?C15ON'>C15 ON </a>");
client.println("<a href='/?C15OFF'>C15 OFF </a>");
client.println("
");
client.println("<a href='/?C16ON'>C16 ON </a>");
client.println("<a href='/?C16OFF'>C16 OFF </a>");
client.println("
");
client.println("<a href='/?ALLOFF'>ALL UNITS OFF </a>");
client.println("
");
client.println("<a href='/?ALLLIGHTSON'>ALL LIGHTS ON </a>");
client.println("
");
client.println("<a href='/?ALLLIGHTSOFF'>ALL LIGHTS OFF </a>");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
///////////////////// decode x10 commands
if(readString.indexOf("ALLOFF") >0)//checks for on
{
myHouse.write(HOUSE_C, ALL_UNITS_OFF,3);
delay(500);
myHouse.write(HOUSE_C, ON,3);
delay(500);
}
/////////////////////////////////////////////////////
if(readString.indexOf("ALLLIGHTSON") >0)//checks for on
{
myHouse.write(HOUSE_C, ALL_LIGHTS_ON,3);
delay(500);
myHouse.write(HOUSE_C, ON,3);
delay(500);
}
/////////////////////////////////////////////////////
if(readString.indexOf("ALLLIGHTSOFF") >0)//checks for on
{
myHouse.write(HOUSE_C, ALL_LIGHTS_OFF,3);
delay(500);
myHouse.write(HOUSE_C, ON,3);
delay(500);
}
/////////////////////////////////////////////////////
if(readString.indexOf("C1ON") >0)//checks for on
{
myHouse.write(HOUSE_C, UNIT_1,3);
delay(500);
myHouse.write(HOUSE_C, ON,3);
delay(500);
}
other x10 decoding goes here, removed from this post as it was too long...
if(readString.indexOf("C16OFF") >0)//checks for off
{
myHouse.write(HOUSE_C, UNIT_16,3);
delay(500);
myHouse.write(HOUSE_C, OFF,3);
delay(500);
}
/////////////////////////////////////////////////////
//clearing string for next read
readString="";
} //end of IF C==\N..
} //end if IF CLIENT.AVAILABLE...
} // end of WHILE CLIENT...
} // end of IF CLIENT....
}