Uno with e-net shield. Works fine with html page turning on and off the one LED you see in the code. I altered the code to include the X10 code examples. Color of wires from RJ11 plug are commented in the code to help any troubleshooting. Using an X10 CM11A 2-way controller.
Issue: I can't get to the point of troubleshooting the actual x10 stuff because something isn't playing nice in the html code at the bottom where I call the X10 commands. With X10 commands at the bottom lines of code, I can turn on and off my one original LED on the html page UNTIL I try to turn on the other button now linked to the X10 command. If I comment out the if(.... statements with the X10 code after it at the bottom, html plays nice and original LED works. So something isn't working down there.
After trying the button linked to X10 commands, webpage also will crash.
Help is appreciated, I edit "working" code from others and include it to do what I want, I don't have a lot of html or C++ experience.
Code:
/*
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)
created 18 Dec 2009
by David A. Mellis
modified 4 Sep 2010
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
#include <x10.h>
const int rxPin = 3; // data receive pin,green
const int txPin = 4; // data transmit pin,yellow
const int zcPin = 2; // zero crossing pin,black
byte CODE1;
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x7B, 0xD4 };
IPAddress ip(10,0,202, 75);
byte gateway[] = {10,0,200,1};
byte subnet[] = {255,255,252,0};
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup()
{
Serial.begin(9600); // open up serial port connection to PC
pinMode(8, OUTPUT); // Set digital pin 8 as output
pinMode(7, OUTPUT); // Set digital pin 7 as output
digitalWrite(zcPin, HIGH);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip,gateway,subnet);
server.begin();
x10.begin(rxPin, txPin, zcPin);
}
void loop()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
String buffer = ""; // Declare the buffer variable
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.print(c); // Send every character read to serial port
buffer+=c; // Assign to the buffer
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<body background=\"http://i111.photobucket.com/albums/n130/sflemon/ClearBlueBackground.jpg\">");
client.println("<font color=white><h1 align=center>8204 Shadowstone Ct. Home Command Page</font></h1>");
client.println("<hr />");
client.println("<hr />");
if (digitalRead(8)){ // 1<-- Display LED status
client.println("<img src=\"http://i111.photobucket.com/albums/n130/sflemon/indicator-green_zps8552e624.png\" width=20 height=20 />");
}else{
client.println("<img src=\"http://i111.photobucket.com/albums/n130/sflemon/indicator-red_zps75caf320.png\" width=20 height=20 />");
}
client.println("
");
// 2<-- Create a form, control output 8
client.print("<FORM action=\"http://10.0.202.75/\" >");
client.print("<P> <div align=left><INPUT type=\"radio\" name=\"status\" value=\"1\">ON" "<INPUT type=\"radio\" name=\"status\" value=\"0\">OFF" "<INPUT type=\"submit\" value=\" Yellow LED \"></div>" "</FORM>");
if (digitalRead(7)){ // 1<-- Display LED status
client.println("<img src=\"http://i111.photobucket.com/albums/n130/sflemon/indicator-green_zps8552e624.png\" width=20 height=20 />");
}else{
client.println("<img src=\"http://i111.photobucket.com/albums/n130/sflemon/indicator-red_zps75caf320.png\" width=20 height=20 />");
}
client.println("
");
// 2<-- Create a form, control output 7
client.print("<FORM action=\"http://10.0.202.75/\" >");
client.print("<P> <div align=left><INPUT type=\"radio\" name=\"status2\" value=\"1\">ON" "<INPUT type=\"radio\" name=\"status2\" value=\"0\">OFF" "<INPUT type=\"submit\" value=\" Red LED \"></div>" "</FORM>");
client.println("
");
client.println("<P> <div align=left><img src=\"http://wwwcache.wral.com/asset/weather/doppler5000/2006/08/07/1001059/ice_2011_dd5k_wake-640x480.jpg\" width=480 height=360 />" "<img src=\"http://wwwcache.wral.com/asset/weather/2008/04/22/2774561/ice_2011_forecast_7day_wral_raleigh-600x450.jpg\" width=480 height=360 />");
client.println("
");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
buffer=""; // Clear the buffer at end of line
} else if (c == '\r') {
if(buffer.indexOf("GET /?status=1")>=0)
digitalWrite(8,HIGH); // Catch ON status and set Yellow LED
if(buffer.indexOf("GET /?status=0")>=0)
digitalWrite(8,LOW); // Catch OFF status and set Yellow LED
if(buffer.indexOf("GET /?status2=1")>=0)
x10.beginTransmission(HOUSE_A);
x10.write(UNIT_1);
x10.write(ON);
x10.endTransmission();
if(buffer.indexOf("GET /?status2=0")>=0)
x10.beginTransmission(HOUSE_A);
x10.write(UNIT_1);
x10.write(OFF);
x10.endTransmission();
}
else {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(2);
// close the connection:
client.stop();
}
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.