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.