Go Down

Topic: SOLVED - Web server not responding somtimes (Read 1 time) previous topic - next topic


Jan 23, 2013, 05:51 pm Last Edit: Jan 25, 2013, 04:30 am by joecatch Reason: 1
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.

Code: [Select]
//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);

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;

       //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("<title>Joe's X10 Remote Control Program</title></head>");
         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("<a href='/?C2ON'>C2 ON </a>");
         client.println("<a href='/?C2OFF'>C2 OFF </a>");
         client.println("<a href='/?C3ON'>C3 ON </a>");
         client.println("<a href='/?C3OFF'>C3 OFF </a>");
         client.println("<a href='/?C4ON'>C4 ON </a>");
         client.println("<a href='/?C4OFF'>C4 OFF </a>");
         client.println("<a href='/?C5ON'>C5 ON </a>");
         client.println("<a href='/?C5OFF'>C5 OFF </a>");
         client.println("<a href='/?C6ON'>C6 ON </a>");
         client.println("<a href='/?C6OFF'>C6 OFF </a>");
         client.println("<a href='/?C7ON'>C7 ON </a>");
         client.println("<a href='/?C7OFF'>C7 OFF </a>");
         client.println("<a href='/?C8ON'>C8 ON </a>");
         client.println("<a href='/?C8OFF'>C8 OFF </a>");
         client.println("<a href='/?C9ON'>C9 ON </a>");
         client.println("<a href='/?C9OFF'>C9 OFF </a>");
         client.println("<a href='/?C10ON'>C10 ON </a>");
         client.println("<a href='/?C10OFF'>C10 OFF </a>");
         client.println("<a href='/?C11ON'>C11 ON </a>");
         client.println("<a href='/?C11OFF'>C11 OFF </a>");
         client.println("<a href='/?C12ON'>C12 ON </a>");
         client.println("<a href='/?C12OFF'>C12 OFF </a>");
         client.println("<a href='/?C13ON'>C13 ON </a>");
         client.println("<a href='/?C13OFF'>C13 OFF </a>");
         client.println("<a href='/?C14ON'>C14 ON </a>");
         client.println("<a href='/?C14OFF'>C14 OFF </a>");
         client.println("<a href='/?C15ON'>C15 ON </a>");
         client.println("<a href='/?C15OFF'>C15 OFF </a>");
         client.println("<a href='/?C16ON'>C16 ON </a>");
         client.println("<a href='/?C16OFF'>C16 OFF </a>");
         client.println("<a href='/?ALLOFF'>ALL UNITS OFF </a>");
         client.println("<a href='/?ALLLIGHTSON'>ALL LIGHTS ON </a>");
         client.println("<a href='/?ALLLIGHTSOFF'>ALL LIGHTS OFF </a>");
         //stopping client

         ///////////////////// decode x10 commands
         if(readString.indexOf("ALLOFF") >0)//checks for on
           myHouse.write(HOUSE_C, ALL_UNITS_OFF,3);
           myHouse.write(HOUSE_C, ON,3);

         if(readString.indexOf("ALLLIGHTSON") >0)//checks for on
           myHouse.write(HOUSE_C, ALL_LIGHTS_ON,3);
           myHouse.write(HOUSE_C, ON,3);

         if(readString.indexOf("ALLLIGHTSOFF") >0)//checks for on
           myHouse.write(HOUSE_C, ALL_LIGHTS_OFF,3);
           myHouse.write(HOUSE_C, ON,3);

         if(readString.indexOf("C1ON") >0)//checks for on
           myHouse.write(HOUSE_C, UNIT_1,3);
           myHouse.write(HOUSE_C, ON,3);

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);
           myHouse.write(HOUSE_C, OFF,3);

         //clearing string for next read

       }  //end of IF C==\N..
     }  //end if IF CLIENT.AVAILABLE...
   }  // end of WHILE CLIENT...
 } // end of IF CLIENT....


Yopu are probably running out of SRAM. Try the F() function to keep those static strings in program memory. Here is an example. Use the same on the rest of those strings.
Code: [Select]
          client.println(F("HTTP/1.1 200 OK")); // Standard HTTP response


And ditch the String class. It's pissing memory away like you've got terabytes of it, instead of 2k.
The art of getting good answers lies in asking good questions.


Thank you guys for the quick reply. That must be the problem as it was working until I added all the extra string code and then it started acting strangely.

I will try the F() function, never heard if it before but then again I am learning something new every day with the Arduino. I ALSO ORDERED A NEW ARDUINO MEGA! This isn't the first time I ran into the limits of the Uno. Last week I had a program that exceeded the 32k ram limit. So what the heck, I ordered the Mega 2560. I already have the original Mega in my robot which I don't want to salavge for this X10 project. Plus it gave me an excuse to order more supplies from Sparkfun! 8-)

Will let you know how the code works when I am done.


UPDATE - I added the F() function for all the client print lines and it seems to have cleared up the issue. I was to use all 16 X10 modules via the web page with no issues. So I guess the 2K ram limit was the problem. Thanks.


And ditch the String class. It's pissing memory away like you've got terabytes of it, instead of 2k.

Guess that just wasn't the problem. Who would have thunk!
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131