adding web support to existing complex sketch

Hello all,
I have built a very functional thermostat using 3 temp sensors, a door sensor and an Adafruit LCD shield. I would like to make it into a simple web server so we can change settings over the internet. I have experience programming ethernet shields but my question is this: How do I modify my existing sketch so while a client is connected, it doesnt affect usability at the unit?
For example, each time thru the main loop, it reads the buttons on the shield. While a client is connected, certain features may not work, unless I include the entire sketch inside the while(client.connected()) loop AND have the entire main loop outside the while() loop as well? I feel like there is a way to optimize it so I dont essentially have to have the main loop twice.

For example:

void loop() {
  if (client) {
    while(client.connected(){
      //main loop code with server code
    }
  }
  //main loop code AGAIN
}

This seems silly. Any advice? Here is my existing sketch with ethernet initialized but no actual ethernet codes in the main loop:
http://pastebin.com/zSbw2i6H
Sorry to not include it in this post but it exceeds the 9600 character limit for a post. Its a long sketch.

Another thought I had about it is maybe the web page code is very simple, and refreshes on the client side very quickly, thus not delaying the main loop very much. For example:

void loop() {
  if (client) {
    while(client.connected()){ 
      //serve web page very quickly then forcing the client to disconnect until it sends another request
    }
  }
  //main loop as it was
}

Does that make sense? I'm just looking to make a very simple web page that allows me to adjust the hold temperature and a few other simple functions.

I took a quick glance at your code.
The webpage might introduce small delays that could influence the repsonse time with the buttons.

The main loop can be done as in your second example. Check if client is connected and also do the rest.
You don't have to do things twice or in a different order.
If the html code is not read from an SD card, but directly from the Arduino to the buffer of the W5100, it will be pretty fast.
I assume that you have an ethernet shield with the W5100 chip.

If you have an Arduino Uno, the code size will be close to the limit. Perhaps you need to upgrade to a Arduino Mega 2560 board.

Ok great, thanks.

I added some very simple HTML code and if its fast enough, it will be wayyyy simpler than I imagined. Theres already some delay in reading the buttons due to all code. You basically just need to press and hold the button for a half second or so anyway.

I have a shield but it's in use. My next one will be arriving soon! :slight_smile: