Arduino Webserver with Temperature Monitor / Control

if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0){
                plen=print_webpage(buf);
            goto SENDTCP;
         }
        cmd=analyse_cmd((char *)&(buf[dat_p+5]));
        if (cmd==1){
             plen=print_webpage(buf);
        }
SENDTCP:  es.ES_make_tcp_ack_from_any(buf); // send ack for http get
           es.ES_make_tcp_ack_with_data(buf,plen); // send data       
      }
    }
  }
        
}
// The returned value is stored in the global var strbuf
uint8_t find_key_val(char *str,char *key)
{
        uint8_t found=0;
        uint8_t i=0;
        char *kp;
        kp=key;
        while(*str &&  *str!=' ' && found==0){
                if (*str == *kp){
                        kp++;
                        if (*kp == '\0'){
                                str++;
                                kp=key;
                                if (*str == '='){
                                        found=1;
                                }
                        }
                }else{
                        kp=key;
                }
                str++;
        }
        if (found==1){
                // copy the value to a buffer and terminate it with '\0'
                while(*str &&  *str!=' ' && *str!='&' && i<STR_BUFFER_SIZE){
                        strbuf[i]=*str;
                        i++;
                        str++;
                }
                strbuf[i]='\0';
        }
        return(found);
}

int8_t analyse_cmd(char *str)
{
        int8_t r=-1;
     
        if (find_key_val(str,"cmd")){
                if (*strbuf < 0x3a && *strbuf > 0x2f){
                        // is a ASCII number, return it
                        r=(*strbuf-0x30);
                }
        }
        return r;
}


uint16_t print_webpage(uint8_t *buf)
{
        char temp_string[10];
        int i=0;
        //char *temp_string="100";
        
        uint16_t plen;
        
        getCurrentTemp(temp_string);
        
        plen=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));
        plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<center><p><h1>Welcome to Arduino Ethernet Shield V1.0  </h1></p> "));
         
        plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<hr>
<form METHOD=get action=\""));
        plen=es.ES_fill_tcp_data(buf,plen,baseurl);
        plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("\">"));
        plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<h2> Current Temperature is </h2> "));
 	plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<h1><font color=\"#00FF00\"> "));
         
       
        while (temp_string[i]) {
                buf[TCP_CHECKSUM_L_P+3+plen]=temp_string[i++];
                plen++;
        }

 	plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("  &#176C</font></h1>
 ") );
        plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=1>"));
        plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Get Temperature\"></form>"));
        plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</center><hr> <p> V1.0 <a href=\"http://www.nuelectronics.com\">www.nuelectronics.com<a>"));
  
        return(plen);
}


void OneWireReset(int Pin) // reset.  Should improve to act as a presence pulse
{
     digitalWrite(Pin, LOW);
     pinMode(Pin, OUTPUT); // bring low for 500 us
     delayMicroseconds(500);
     pinMode(Pin, INPUT);
     delayMicroseconds(500);
}

void OneWireOutByte(int Pin, byte d) // output byte d (least sig bit first).
{
   byte n;

   for(n=8; n!=0; n--)
   {
      if ((d & 0x01) == 1)  // test least sig bit
      {
         digitalWrite(Pin, LOW);
         pinMode(Pin, OUTPUT);
         delayMicroseconds(5);
         pinMode(Pin, INPUT);
         delayMicroseconds(60);
      }
      else
      {
         digitalWrite(Pin, LOW);
         pinMode(Pin, OUTPUT);
         delayMicroseconds(60);
         pinMode(Pin, INPUT);
      }

      d=d>>1; // now the next bit is in the least sig bit position.
   }
   
}

byte OneWireInByte(int Pin) // read byte, least sig byte first
{
    byte d, n, b;

    for (n=0; n<8; n++)
    {
        digitalWrite(Pin, LOW);
        pinMode(Pin, OUTPUT);
        delayMicroseconds(5);
        pinMode(Pin, INPUT);
        delayMicroseconds(5);
        b = digitalRead(Pin);
        delayMicroseconds(50);
        d = (d >> 1) | (b<<7); // shift d to right and insert b in most sig bit position
    }
    return(d);
}


void getCurrentTemp(char *temp)
{  
  int HighByte, LowByte, TReading, Tc_100, sign, whole, fract;

  OneWireReset(TEMP_PIN);
  OneWireOutByte(TEMP_PIN, 0xcc);
  OneWireOutByte(TEMP_PIN, 0x44); // perform temperature conversion, strong pullup for one sec

  OneWireReset(TEMP_PIN);
  OneWireOutByte(TEMP_PIN, 0xcc);
  OneWireOutByte(TEMP_PIN, 0xbe);

  LowByte = OneWireInByte(TEMP_PIN);
  HighByte = OneWireInByte(TEMP_PIN);
  TReading = (HighByte << 8) + LowByte;
  sign = TReading & 0x8000;  // test most sig bit
  if (sign) // negative
  {
    TReading = (TReading ^ 0xffff) + 1; // 2's comp
  }
  Tc_100 = (6 * TReading) + TReading / 4;    // multiply by (100 * 0.0625) or 6.25

  whole = Tc_100 / 100;  // separate off the whole and fractional portions
  fract = Tc_100 % 100;


	if(sign) temp[0]='-';
	else 		 temp[0]='+';
	
        if(whole/100==0)
           temp[1] =' ';
        else
	  temp[1]= whole/100+'0';
	temp[2]= (whole-(whole/100)*100)/10 +'0' ;
	temp[3]= whole-(whole/10)*10 +'0';
	
	temp[4]='.';
	temp[5]=fract/10 +'0';
	temp[6]=fract-(fract/10)*10 +'0';
	
	temp[7] = '\0';


	
}

why dont use DallasTemperatureControl library?

Dallas's librairy?

Btguillaume:
Dallas's librairy?

Yes, why don't use Dallas's library?

what's that I juste done a quick google's search, but nothing interrested....

can you explain what's that?

There's an Arduino library for "one wire" devices like the DS18B20.

http://playground.arduino.cc/Learning/OneWire

Btguillaume:
what's that I juste done a quick google's search, but nothing interrested....

can you explain what's that?

I mean this library:
http://milesburton.com/Dallas_Temperature_Control_Library

Hi everybody! I'm newbie and I want to make similar project. But I use Wiznet W5100 Ethernet Shield... So my question is how to change the code for the Arduino Ethernet Shield? ?an anybody help me?

Hi, this code is really nice! I modified it a little bit to be used with LM35DZ.
Now I need to implement the basic authentication (otherwise everybody can enter my home system and switch on my heater!!!) but I am completely lost!!! Could someone help me please?
thanks!

thermostat.ino (11 KB)

The client will make a request to your Arduino, typically with no authorization.

GET /foo HTTP/1.0
Host: foo.bar.com

Your arduino should respond with a request for authorization

403 Forbidden

The client will redo its request with credentials

GET /foo HTTP/1.0
Host: foo.bar.com
Authorization: Basic base_64_encoded_username_password

Your arduino can either decode the base64 encoded string or simply perform a match against a known base64 encoded string. An example of a an encoded Header, using the username "username" and password "password" separated by a colon in the standard format of "username:password" would look like:

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

In each instance there will be additional HTTP headers present, such as "User-Agent:" or "Accept:", but what I have above are the only important ones.

Putting that more simply, for any request that you receive you should verify that there is an Authorization: header and that the encoded string contains a proper username/password. Continue processing the request as usual if so. If not, reply with a 403 Forbidden response.

Hi, could you help me to integrate it in my code?
I am really a newbie...
Thanks!

Hello all, congratulations for the project, share code and give attention to all the questions.

I'm from Brazil and I have a system that informs the lack of electricity SMS.

I connected one shild GPRS on a ATMEGA328 (standalone, I made a simple board), it connected two power sensors and temperature.

When power a generator should be fired and then he sends an SMS with this information.

I added a network card that I also have this information via the web.

Did you or anyone have time to help me with this?
Pessimo'm programming ...

Hugs to all.

Sergio

Nice project, but I cant read temp value over the page :~ I can read only 0.6 C and not changing. Please help.

One small issue is that negative temperatures are shown as positive value.

Im currently having a temp of -4 deg C and the webserver shows 4 deg C.

Also: how can I modify to only have temp showing. I have done it on what you see but when I try to remove all with ths SSR's The web page won't load.

EDIT:

Could I just simply use signbit to add in a "-" ?

Kind of the same way as tou use the SSR bytes for on and off??

Reply to " elektrokan "
Your problem is here

byte sensor1[8] = { 0x28, 0x61, 0x24, 0xC5, 0x03, 0x00, 0x00, 0x51};  // User Defined Temperature Sensor Address 1

Use the temperature example from the Onewire Library to find your DS18X20's address , then copy and replace the existing address with a new one.

Nice project !
How to edit the schetch to use ethernet shield based on wiznet5100 an DHT22 tmperature sensor ?

Please could you tell me here insert links to the library used to 28j60. thank you

Please is this thread still alive? Could someone here insert links to the library used to 28J60? Thank you.

daton:
Please is this thread still alive? Could someone here insert links to the library used to 28J60? Thank you.

http://jeelabs.net/projects/ethercard/wiki

After uploading code i am not able to load page,

i have changed IP address as per my req.

need help