Help with online Thermostat Please

The code is to large to post in text so I have attached the sketch instead.
You can see the thermostat @ http://192.40.125.129:801/ Feel free to play with it. I have put some debugging on the displayed website as well.

That I know of, these are my issues...

  1. When I press the web button for "heating mode", or "cooling mode" the sketch goes through both heating and cooling mode loops for just a brief second and then exits. However, when I press the web button for "recirculation mode" it stays in the recirc loop.

  2. I have a text form for submitting a new temperature that I want the thermostat set to. When I put in a value and click the submit button the only thing that happens is the address bar gets an updated address... (http://172.16.32.178:801/?S=75)
    I am trying to receive my new set temp through client.parseint and save it to a variable (setTemp) ... setTemp = client.parseInt();
    Instead I am always receiving 172 on client.parseint.

Any help would be really great! I have been struggling with this.

Online_Thermostat_Trial_3.ino (9.52 KB)

modsbyus:
The code is to large to post in text so I have attached the sketch instead.

LOL... OOPS... sorry. Its there now

That I know of, these are my issues...

I'm pretty sure that the problem is your code.

The first one is likely that you have no tolerance for heating or cooling. That is, the temperature range for heating overlaps that for cooling, at at least one point.

The second is probably that you don't have any code that cares what the client requests. The code you didn't actually share simply returns the same response for every request.

PaulS... Please refrain from "helping" me. you have not been of any "help" in the past. Thanks!

Calling functions seems in conflict with the thermostat paradigm to me.

Don't you really just want to create 4 States?

Cool
Heat
Recirc
Off

then accept inputs to modify the state (set points) or change the states...

I'd take a look at the Nick Gammon State Machine example.

BulldogLowell:
Calling functions seems in conflict with the thermostat paradigm to me.

What do you mean?

Don't you really just want to create 4 States?

Cool
Heat
Recirc
Off

then accept inputs to modify the state (set points) or change the states...

I thought thats what I did?

I'd take a look at the Nick Gammon State Machine example.

I don't really get what I'm looking at here...

modsbyus:
What do you mean?

I mean, I hardware select from four possible states, COOL, HEAT, FAN or OFF. the thermostat then behaves differently depending on that setting, even though I am using the same buttons to control it (set point).

I thought thats what I did?

Actually, you have one state that is calling some functions.

I don't really get what I'm looking at here...

you can experiment with his example to see what's happening.

The link you provided was for something other that the state machine example. I found it and have been working with it. I tried an implementation of it in my thermostat but it doesn't seem to do anything. my thermstate (the state that should be stored) always comes back as the number 1.
I uploaded the new code to this post.... really, I did.. LOL :wink:

Online_Thermostat_Trial_4.ino (10.8 KB)

After thinking about it a bit more it seemed like I would have to call the thermstate in the functions so I changed it a bit. Still no good though.

Online_Thermostat_Trial_4.ino (10.9 KB)

you are getting there...

you have some cut/paste errors, I'm sure you saw.

client.println(thermstate);
            client.println("
");
            client.println("<p>Base Code by Rui Santos at http://randomnerdtutorials.com. Modified by Gary Boyce http://www.modsbyus.com </p>");
            client.println("
");
            client.println("</BODY>");
            client.println("</HTML>");

Can you give me some insight as to why I am receiving a 1 for my thermstate instead of the actual thermstate? That would be very helpful in dubugging if I could fix that.

            if (readString.indexOf("?button1on") > 0) {
              switch (thermstate) {
                  thermstate = coolON;
                case coolON:
                  cool();
                  break;

              }

Using a switch statement generates more code than an if statement, when there are less than three cases. Assigning a value to themrmstate in a switch statement, outside of a case statement is wrong. Nothing should happen in a switch statement that is not part of a case statement.

PaulS:

            if (readString.indexOf("?button1on") > 0) {

switch (thermstate) {
                  thermstate = coolON;
                case coolON:
                  cool();
                  break;

}



Using a switch statement generates more code than an if statement, when there are less than three cases. Assigning a value to themrmstate in a switch statement, outside of a case statement is wrong. Nothing should happen in a switch statement that is not part of a case statement.

So...
Like this.

            if (readString.indexOf("?coolon") > 0) {
              switch (thermstate) {

                case coolON:
                  thermstate = coolON;
                  cool();
                  break;

              }

Or did I completely miss what you were saying?

Can anyone help me understand what I have done wrong here? I have followed http://www.gammon.com.au/forum/bbshowpost.php?id=12316 to the best of my ability and instead of thermstate being updated with one of these (coolON, thermOFF, heatON, recircON) it just always gets a number 1 . I'm open to just getting a really good resource that explains what to do and not to do. From what I have read enum isn't really any different than int in that it is for storing an integer. I'm not sure how any of this is to work if I'm trying to store a word!

enum { coolON, thermOFF, heatON, recircON } thermstate = thermOFF;
if (readString.indexOf("?coolon") > 0) {
              switch (thermstate) {

                case coolON:
                  thermstate = coolON;
                  cool();
                  break;

              }
              if (readString.indexOf("?heaton") > 0) {
                switch (thermstate) {

                  case heatON:
                    thermstate = heatON;
                    heat();
                    break;
                }
                if (readString.indexOf("?recircon") > 0) {
                  switch (thermstate) {

                    case recircON:
                      thermstate = recircON;
                      recirc();
                      break;
                  }
                  if (readString.indexOf("?thermoff") > 0) {
                    switch (thermstate) {

                      case thermOFF:
                        thermstate = thermOFF;
                        off();
                        break;
                    }

modsbyus:
instead of thermstate being updated with one of these (coolON, thermOFF, heatON, recircON) it just always gets a number 1

In that case I suggest you look at the code which is setting thermstate to 1 and work out why that code is executing.

Or did I completely miss what you were saying?

I'm afraid you did. The switch statement with only one case is wrong.

Setting thermstate to coolON when it is already equal to coolON seems pointless.

PaulS:

Or did I completely miss what you were saying?

I'm afraid you did. The switch statement with only one case is wrong.

Setting thermstate to coolON when it is already equal to coolON seems pointless.

Thanks! Is this a bit better?

            if (readString.indexOf("?coolon") > 0) {
              thermstate == 2;
            }
            if (readString.indexOf("?heaton") > 0) {
              thermstate == 4;
            }
            if (readString.indexOf("?recircon") > 0) {
              thermstate == 5;
            }
            if (readString.indexOf("?thermoff") > 0) {
              thermstate == 3;
            }
            if (c == 'S') {
              Serial.print("Set To ");
              setTemp = client.parseInt();
              Serial.println(setTemp);
              break;
            }
            //clearing string for next read
            readString = "";
            Serial.println(currentTemp);

            switch (thermstate) {

              case 2:
                cool();
                break;

              case 4:
                heat();
                break;

              case 5:
                recirc();
                break;

              case 3:
                off();
                break;

}
          }

Online_Thermostat_Trial_4.ino (10.6 KB)

I also have found that none of my if statements that are dependent on the readString will run because I keep receiving

readString: GET /?coolon HTTP/1.1

thermstate: 0
73
readString: GET /favicon.ico HTTP/1.1

thermstate: 0
73

My if staements are looking for the button press "readString: GET /?coolon HTTP/1.1" but after that comes through I also get "readString: GET /favicon.ico HTTP/1.1". I don't know where this favicon.ico is coming from. Its not in my code anywhere that I can find. I'll be doing some research in the mean time but I thought it would be good to have here for anyone else with the same problem.

Found that if I add

            client.println("<link rel='shortcut icon' href='data:image/x-icon;,' type='image/x-icon'>"); 
            client.println("<TITLE>Online Digital Thermostat</TITLE>");

then I don't have GET /favicon.ico HTTP/1.1 coming through. It did't help my if statements though. :frowning: