Arduino Forum

Community => Exhibition / Gallery => Topic started by: randyrob on Jul 16, 2012, 04:56 am

Title: Arduino Webserver with Temperature Monitor / Control
Post by: randyrob on Jul 16, 2012, 04:56 am
Hey Guys,

I spent the last few days coding up a Webserver for the Arduino with the Aim of using several of them for different purposes
throughout my house. So I made the code as generic as possible. I plan on using one to control a HLT (Hot Liquor Tank) on a Brewery,
One for Fermentation Control and one to simply switch on my Coffee Machine remotely but I can think of a multitude of uses if
I can knock up my own boards/enclosures cheap enough.

I grabbed the cheapest parts I could find on eBay so I'm using an Arduino Nano Clone, Enc28J60 Ethernet, Dallas Ds18b20 Temperature Sensor & an LED (to replicate a Solid State Relay - SSR)
You could easily get this sketch working with any Arduino & also a Wiznet w5100 with only a few lines of code change.

(http://www.halfluck.com/source/webserver/arduinosm.jpg)

Parts - Ethernet Board on the left, Arduino on the Right.

(http://www.halfluck.com/source/webserver/webserver_auto.png)

Browser Output (Auto Mode)

(http://www.halfluck.com/source/webserver/webserver_manual.png)

Browser Output (Manual Mode)

Source Code ==> http://www.halfluck.com/source/webserver/TempControllerWebServer.ino (http://www.halfluck.com/source/webserver/TempControllerWebServer.ino)

Thanks for Looking, Hope others find the code useful

Cheers Rob.
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: randyrob on Jul 19, 2012, 09:06 am
Hey Guys,

My Arduino is still running strong with the above sketch, and I had some time at lunch so I knocked up a Shield and sent it of to get fabbed.
It will allow me to keep everything together and a small footprint (51cmx51cm)
It has screw down Terminals for 4 x SSR's and as many Temperature sensors as I want, a pin header for Ethernet as well which supports both
ENC28J60 & Wiznet Chips & 2 pin headers for each pin on the Arduino.

(http://www.halfluck.com/source/webserver/shield.png)

Cheers Rob.
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: randyrob on Jul 24, 2012, 07:01 am
I end up re-writing my code using a better Ethernet Library (EtherCard)
I'm really happy with how it is running, most of my bits have arrived from china just waiting on the Custom PCB to arrive.

(http://www.halfluck.com/source/webserver/auto.jpg)

(http://www.halfluck.com/source/webserver/manual.jpg)

Cheers Rob.
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: LaStrada on Jul 24, 2012, 03:33 pm
Nice work! :) Thanks for sharing source code.

I'm currently working on a similar solution, but I'm using a web server running Django to control my arduinos. I needed a good example to show how I could use the EtherCard Library.
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: warunasanjaya11 on Jul 24, 2012, 06:49 pm
I want know whether Arduino Nano Clone is a USB Microcontroller or not? .Because I found a product in website named http://iteadstudio.com and the product name is Arduino Nano USB Microcontroller v3 (Clone version) .As you mentioned in your description the these words "Arduino" ,"Nano" and "Clone" words are containing in the product name Arduino Nano USB Microcontroller v3 (Clone version). If you mentioned the same product can you please tell me the prize you bought that part and from where you bought it. So I can compare it with the prizes in markets and buy the cheapest one

Dashquid (http://dashquid.com)
fatlossprofessional.co.uk (http://fatlossprofessional.co.uk)
fatlossprofessional (http://fatlossprofessional.co.uk/how-to-lose-weight-fast/)
mobilehelper (http://mobilehelper.co.uk)
securetrip (http://securetrip.co.uk)
whichpetcover (http://whichpetcover.com)
google (http://google.com)
abc (http://abc.com)
facebook (http://facebook.com)
craigslist (http://craigslist.com)
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: dtokez on Jul 24, 2012, 07:10 pm
Great job!
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: randyrob on Jul 25, 2012, 03:34 am
warunasanjaya11,

Yes the Nano is USB. The one on the website you listed is the same as the one I got.

I just grabbed the Nano ($15 inc post) and Ethernet Controller ($5 inc post) from dealextreme, but ebay had similar prices.

Amazing how cheap all this stuff has gotten over the last couple of years.

Cheers Rob.
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: RichieC on Aug 08, 2012, 10:50 pm
Hi

I really like your project, it has finally got me to understanding some of the programming involved in completing this.

You have changed your sketch from version one, do you have any plans to post the new sketch?

I'd like to compare the two new vs old.

Thanks you have been a great help.

Rich
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: randyrob on Aug 09, 2012, 10:11 am
Hey Rich,

Thanks much appreciated.

When I changed the sketch to the Ethercard library I updated it on the link too. So that is latest version.

Still waiting on the Custom PCB to arrive to finish the project.....

Cheers Rob.

Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: iisfaq on Aug 12, 2012, 09:29 pm
Hi looks good - I have a question on the PCB?

Did you order just one? or a few?

What was the cost? including shippping?

And who did it?

I want to get some board made but still not sure of where to get it done. I am in New Zealand.

Also what did you use for the board design?

Cheers

Chris
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: randyrob on Aug 13, 2012, 01:41 am
>> Hi looks good - I have a question on the PCB?

Hello Chris

>> Did you order just one? or a few?

I ordered 3 (the minimal)

>>What was the cost? including shippping?

$5 per square inch for three copies of your design and postage was $5, so If you can fit it on a square inch works out to be ~$3.30 a board

Pricing is here http://oshpark.com/pricing (http://oshpark.com/pricing)

>>And who did it?

These guys http://oshpark.com/ (http://oshpark.com/)
Great site and very easy to use and deal with.

>I want to get some board made but still not sure of where to get it done. I am in New Zealand.

I am in Australia so not to far :)

>Also what did you use for the board design?

I used Eagle free version

http://www.cadsoftusa.com/eagle-pcb-design-software/?language=en (http://www.cadsoftusa.com/eagle-pcb-design-software/?language=en)

easy enough to use and there is heaps of guides on youtube, instructables etc.

Rob.


Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: iisfaq on Aug 13, 2012, 02:31 am
Thanks Rob

Appreciate the quick response

chris
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: michaelelcano on Aug 19, 2012, 12:35 am
Im having trouble with this ethernet module. What pinout did you use with the jeelabs library.
thanks Michael
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: BlueJakester on Aug 19, 2012, 02:33 am
Looks great! Well done!

Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: randyrob on Aug 20, 2012, 05:32 am

Im having trouble with this ethernet module. What pinout did you use with the jeelabs library.
thanks Michael


Hey Michael,

I used :

Arduino ==> Ethernet Controller
============================
2 ==> INT
10 ==> CS
11 ==> SI
12 ==> SO
13 ==> SCK
Reset ==> RST

and +3.3v, Ground

also make sure that you are calling pin 10 at the start of the sketch like os

if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)

Lemme know if you get stuck...


I got the PCB's on friday, soldered it up, put it inside an enclosure and gave it a good run in on the weekend and it works perfectly, very happy, bit of a tight fit inside the enclosure tho!

(http://24.media.tumblr.com/tumblr_m8wh67CI6d1re5xnco1_1280.jpg)

(http://24.media.tumblr.com/tumblr_m8wh67CI6d1re5xnco2_1280.jpg)

(http://24.media.tumblr.com/tumblr_m8wh67CI6d1re5xnco3_1280.jpg)

(http://25.media.tumblr.com/tumblr_m8wh67CI6d1re5xnco4_1280.jpg)

(http://24.media.tumblr.com/tumblr_m8wh67CI6d1re5xnco5_1280.jpg)

(http://24.media.tumblr.com/tumblr_m8wh67CI6d1re5xnco6_1280.jpg)

Cheers Rob.
Title: Thanks, formatting of sketch.
Post by: tochinet on Aug 29, 2012, 11:40 am
Thanks Rob for sharing this app. I'm in your tracks (but way behind) on a DINo, with Cosm publishing.

If that helps, I reformatted your sketch (mainly strings and comments) so that it prints correctly. Attached.
Apparently Arduino doesn't word wrap, and fails to print if you lower the margins.

I checked it still compiles, but can't check if it still works OK ;-)
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: tochinet on Aug 29, 2012, 12:56 pm
@Rob,

I tried to integrate part of your sketch in mine, and it failed to compile because I didn't include BufferFiller. Strange, as my sketch already included some web page(s?) using the Stash, and I don't see you using it. Any idea on the inner working that could help me understand ?
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: drummin89 on Nov 04, 2012, 08:38 pm
Thanks for the source code.

I'm new to arduino and html code as well and for my first big project I want to make a web controlled thermostat. I have both an uno and a mega and I am also using a wiznet 5100 ethernet shield. Plan is to wire a set of contacts from my relay module parallel with the thermostat on the wall. In the end I'd like to have a temperature schedule set up on the web page where I can set a different temperature every 3 hours for all 7 days. But for now I'd just like to be able to set the target temperature through the web page.

I was happy when I saw your code cause I needed an example to go off of. Problem is I am using the wiznet 5100 ethernet chip.

Anyways do you know what needs to be changed to get your code to work with the wiznet chip?

I am also using an analog temperature sensor so I edited out all the code for the dallas sensor and added in code for the analog sensor.

Thanks
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: drummin89 on Nov 11, 2012, 05:03 pm
can someone please explain how the current temperature and the target temperature get displayed on the web page.

I don't understand this
    "Temperature: <b>"
    "<br />"
    "<font size=""7"">"
    "$D.$D &deg;C</font></b>"   
and this
    "Target Temperature: <b>"
    "$D.0 &deg;C</b>"

what is SD.SD and SD.0  are those somehow bound to currenttemp and targettemp?

I'd like to edit the original code to display a couple other values besides the current and target temperatures.

Thanks,
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: drummin89 on Nov 24, 2012, 10:21 pm
Finally realized how the ethercard code works and was able to edit your original code. Added 3 more text input boxes to the web page. My code has day and night temperature set points as well as day and night start times. I added a real time clock so it will automatically change the target temp based on the times i set on the web page. Thanks again for the source code, I didn't know what I was getting into when I got the Enc28J60 module.

Code: [Select]
#include <EtherCard.h>
#include <EEPROM.h>
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

char DayTempTextbox[4];               // Data in text box
char NightTempTextbox[4];             // Data in text box
char DayTimeTextbox[4];               // Data in text box
char NightTimeTextbox[4];             // Data in text box

// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0xAA,0xAA,0xAA,0xAA,0xAA,0xAA };
static byte myip[] = { 192,168,1,102 }; //used for static IP

byte Ethernet::buffer[1000];
BufferFiller bfill;

byte TargetTemp = 65;                     
byte DayTempSP = 70;
byte NightTempSP = 68;
byte DayStartTime = 7;
byte NightStartTime = 20;
byte value;

byte TempSensor = A3;
byte HeatONRelay1 = 3;
byte HeatONRelay2 = 4;

const int numReadings = 15;
byte TempReading[numReadings];
byte TempIndex = 0;
int TempTotal = 0;

byte RoomTemperature = 0;
byte TempDBMax = 71;
byte TempDBMin = 69;
byte TempDeadBandSP = 1;

byte Hour = 12;
byte Minute = 24;
byte Second = 36;
byte Month = 11;
byte Day = 23;
int Year = 2012;

//====================================================================================================
void setup () {
//====================================================================================================
  if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0);
  ether.staticSetup(myip);
  Wire.begin();
  RTC.begin();
  pinMode(HeatONRelay1, OUTPUT);          // sets the digital pin as input
  pinMode(HeatONRelay2, OUTPUT);          // sets the digital pin as input
 
  analogReference(INTERNAL); 
 
  DayTempSP = EEPROM.read(0);
  NightTempSP = EEPROM.read(1);
  DayStartTime = EEPROM.read(2);
  NightStartTime = EEPROM.read(3);
   
}

//====================================================================================================

const char http_OK[] PROGMEM =
    "HTTP/1.0 200 OK\r\n"
    "Content-Type: text/html\r\n"
    "Pragma: no-cache\r\n\r\n";

const char http_Found[] PROGMEM =
    "HTTP/1.0 302 Found\r\n"
    "Location: /\r\n\r\n";

const char http_Unauthorized[] PROGMEM =
    "HTTP/1.0 401 Unauthorized\r\n"
    "Content-Type: text/html\r\n\r\n"
    "<h1>401 Unauthorized</h1>";

//====================================================================================================
static word homePage() {
//====================================================================================================

//$D = word data type
//$L = long data type
//$S = c string
//$F = progmem string
//$E = byte from the eeprom.

  char* Heatstat;
  if ( digitalRead(HeatONRelay1) == HIGH ) {
    Heatstat = "On" ; }
  else {
    Heatstat = "Off"; }
   
  bfill.emit_p(PSTR(
  "HTTP/1.0 200 OK\r\n"
  "Content-Type: text/html\r\n"
  "Pragma: no-cache\r\n"
  "\r\n"
  "<!DOCTYPE html>"
  "<html><head>"
  "<meta http-equiv='refresh' content='10'/>"
  "<title>ArduStat</title>"
  "<body bgcolor=""#99CCFF"">"
  "<center>"
  "<hr />"
  "Temperature: <b>"
  "<br />"
  "<font size=""5"">"
  "$D &deg;F</font></b>"   
  "<br />"
  "Current Target Temperature: <b>"
  "$D &deg;F</b>"
  "<br />"
  "Heat is <b>$S</b> "
  "<hr />"
  "Current Temperature Setpoint: <b><font size=""4"">$D &deg;F</font></b>"
  "<form><input type=text name=daytemp size=4> <input type=submit value=Ok> </form>"
  "Current Start Time: <b><font size=""4"">$D</font></b>"     
  "<form><input type=text name=daytime size=4> <input type=submit value=Ok> </form>"
  "Current Temperature Setpoint: <b><font size=""4"">$D &deg;F</font></b>"
  "<form><input type=text name=nighttemp size=4> <input type=submit value=Ok> </form>" 
  "Current Start Time: <b><font size=""4"">$D</font></b>"
  "<form><input type=text name=nighttime size=4> <input type=submit value=Ok> </form>"
  "<hr />"
  "Date: $D/$D/$D Time: $D:$D:$D "     
  "</center></body></html>"),
  RoomTemperature, TargetTemp, Heatstat, DayTempSP, DayStartTime, NightTempSP, NightStartTime, Month, Day, Year, Hour, Minute, Second );
  return bfill.position();
         
}
//====================================================================================================
void loop () {
//====================================================================================================

  DateTime now = RTC.now();
  Month = now.month();
  Day = now.day();
  Year = now.year();
  Hour = now.hour();
  Minute = now.minute();
  Second = now.second();
 
  TempTotal = TempTotal - TempReading[TempIndex];
  TempReading[TempIndex] = ((analogRead(TempSensor)/9.31)-3);
  TempTotal = TempTotal + TempReading[TempIndex];
  TempIndex = TempIndex + 1;
  if (TempIndex >= numReadings) {
    TempIndex = 0; }
  RoomTemperature = TempTotal / numReadings;
 
  if ((Hour >= DayStartTime) & (Hour < NightStartTime)) {
    TargetTemp = DayTempSP; }
     
  if ((Hour >= NightStartTime) | (Hour < DayStartTime)) {
    TargetTemp = NightTempSP; }
 
  TempDBMin = (TargetTemp - TempDeadBandSP);
  TempDBMax = (TargetTemp + TempDeadBandSP); 
 
  if (RoomTemperature < TempDBMin) {
    digitalWrite(HeatONRelay1, HIGH);
    digitalWrite(HeatONRelay2, HIGH); }
  if (RoomTemperature > TempDBMax) {
    digitalWrite(HeatONRelay1, LOW);
    digitalWrite(HeatONRelay2, LOW); }
 
  word len = ether.packetReceive();
  word pos = ether.packetLoop(len);
 
  if (pos) {
    delay(1);   // necessary for my system //TODO
    bfill = ether.tcpOffset();
    char *data = (char *) Ethernet::buffer + pos;
    if (strncmp("GET /", data, 5) != 0) {
      bfill.emit_p(http_Unauthorized); }
    else {
      data += 5;
      if (data[0] == ' ') {
        homePage(); }
      else if (strncmp( "?daytemp=" , data , 8 ) == 0) {
        if (ether.findKeyVal(data + 1, DayTempTextbox , sizeof DayTempTextbox , "daytemp") > 0) {
          value = atoi(DayTempTextbox);   // command to convert a string to number
          if ((value >= 55) & (value <= 80)) {
            DayTempSP = value;
            EEPROM.write(0, value); }
        }
        bfill.emit_p(http_Found);
      }
      else if (strncmp( "?daytime=" , data , 8 ) == 0) {
        if (ether.findKeyVal(data + 1, DayTimeTextbox , sizeof DayTimeTextbox , "daytime") > 0) {
          value = atoi(DayTimeTextbox);   // command to convert a string to number
          if ((value > 0) & (value <= 24)) {
            DayStartTime = value;
            EEPROM.write(2, value); }
        }
        bfill.emit_p(http_Found);
      }
      else if (strncmp( "?nighttemp=" , data , 10 ) == 0) {
        if (ether.findKeyVal(data + 1, NightTempTextbox , sizeof NightTempTextbox , "nighttemp") > 0) {
          value = atoi(NightTempTextbox);   // command to convert a string to number
          if ((value >= 55) & (value <= 80)) {
             NightTempSP = value;
            EEPROM.write(1, value); }
        }
        bfill.emit_p(http_Found);
      } 
      else if (strncmp( "?nighttime=" , data , 10 ) == 0) {
        if (ether.findKeyVal(data + 1, NightTimeTextbox , sizeof NightTimeTextbox , "nighttime") > 0) {
          value = atoi(NightTimeTextbox);   // command to convert a string to number
          if ((value > 0) & (value <= 24)) {
            NightStartTime = value;
            EEPROM.write(3, value); }
        }
        bfill.emit_p(http_Found);
      }
      ether.httpServerReply(bfill.position());
    }
  }
}


webpage:
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: AlexTroy on Feb 03, 2013, 12:30 pm
Hello!
Very interesting thermostat you get. Have a question. As I understand it 18b20 address must be specified manually in the sketch, how to connect the sensor to a different address, without flashing?

Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: alvydas001 on Feb 13, 2013, 06:31 pm
Please read there:
http://www.homebrewtalk.com/f51/arduino-networked-temperature-monitor-340294/index2.html#post4286666
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: Btguillaume on Feb 14, 2013, 04:13 am
Is this code source work if I only copy/pastre to my enc28j60 ethenet shield?

Does this thermostat can send email if the temperature range is below or under the value I preset?


Im very interrested to reproduce this thing, it's awsome! thanks for sharing and let me know!


It could be cool to share an HOW TO for beginners like me :)
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: alvydas001 on Feb 14, 2013, 11:16 am
I think that e-mail can send only arduino mega 2560, arduino uno insufficient memory, if you want to supplement the program

http://www.lucadentella.it/en/2012/12/16/enc28j60-e-arduino-12/, https://raw.github.com/lucadentella/enc28j60_tutorial/master/_12_SkebbySMS/_12_SkebbySMS.ino
https://github.com/jcw/ethercard/issues/65
http://forum.jeelabs.net/comment/9920#comment-9920
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: Btguillaume on Feb 14, 2013, 01:41 pm
Okay i think that would help.

I'm realy bad in programming, My project is to take the entire web temperature fo enc28j60 code and modify it to send email when the value is under or over the preset.



Thanks for help and shared links!
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: alvydas001 on Feb 14, 2013, 01:57 pm
You really need a more powerful Arduino with more RAM (mega2560) or can try http://ksduino.org, http://open.sen.se/, https://www.thingspeak.com/ http://exosite.com/products/portals cloud. Ksduino and http://www.pushingbox.com/ support ENC28J60.
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: Btguillaume on Feb 14, 2013, 05:31 pm

You really need a more powerful Arduino with more RAM (mega2560) or can try ksduino.org, http://open.sen.se/, https://www.thingspeak.com/ http://exosite.com/products/portals cloud. Ksduino and http://www.pushingbox.com/ support ENC28J60.


Duemilanove + ethernetshield enc28j60 should be a great setup?
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: alvydas001 on Feb 15, 2013, 08:36 am
The full terms of reference in the scene!
Otherwise, there is nothing you will not respond.
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: Btguillaume on Feb 15, 2013, 02:52 pm

The full terms of reference in the scene!
Otherwise, there is nothing you will not respond.




Sry for my bad english... I don't understand....   :<
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: alvydas001 on Feb 15, 2013, 03:21 pm
My English is very bad, too :-)
have to say what you wish to do so, must complete the task conditions, it is difficult to advise otherwise.
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: Btguillaume on Feb 15, 2013, 06:50 pm
Speak French?

Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: Btguillaume on Feb 16, 2013, 05:13 pm
Okay, so I have the code right here :

Code: [Select]
#include "etherShield.h"

// please modify the following two lines. mac and ip have to be unique
// in your local area network. You can not have the same numbers in
// two devices:
static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x24};
static uint8_t myip[4] = {192,168,1,15};
static char baseurl[]="http://192.168.1.15/";
static uint16_t mywwwport =80; // listen port for tcp/www (max range 1-254)
// or on a different port:
//static char baseurl[]="http://10.0.0.24:88/";
//static uint16_t mywwwport =88; // listen port for tcp/www (max range 1-254)
//


#define BUFFER_SIZE 500
static uint8_t buf[BUFFER_SIZE+1];
#define STR_BUFFER_SIZE 22
static char strbuf[STR_BUFFER_SIZE+1];

EtherShield es=EtherShield();

// prepare the webpage by writing the data to the tcp send buffer
uint16_t print_webpage(uint8_t *buf);
int8_t analyse_cmd(char *str);
// get current temperature
#define TEMP_PIN  3
void getCurrentTemp( int *sign, int *whole, int *fract);

void setup(){
 
  /*initialize enc28j60*/
es.ES_enc28j60Init(mymac);
  es.ES_enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz
  delay(10);
       
/* Magjack leds configuration, see enc28j60 datasheet, page 11 */
// LEDA=greed LEDB=yellow
//
// 0x880 is PHLCON LEDB=on, LEDA=on
// enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
es.ES_enc28j60PhyWrite(PHLCON,0x880);
delay(500);
//
// 0x990 is PHLCON LEDB=off, LEDA=off
// enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
es.ES_enc28j60PhyWrite(PHLCON,0x990);
delay(500);
//
// 0x880 is PHLCON LEDB=on, LEDA=on
// enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
es.ES_enc28j60PhyWrite(PHLCON,0x880);
delay(500);
//
// 0x990 is PHLCON LEDB=off, LEDA=off
// enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
es.ES_enc28j60PhyWrite(PHLCON,0x990);
delay(500);
//
 // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
 // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
 es.ES_enc28j60PhyWrite(PHLCON,0x476);
delay(100);
       
 //init the ethernet/ip layer:
 es.ES_init_ip_arp_udp_tcp(mymac,myip,80);
 
 // initialize DS18B20 datapin
   digitalWrite(TEMP_PIN, LOW);
   pinMode(TEMP_PIN, INPUT);      // sets the digital pin as input (logic 1)


}

void loop(){
 uint16_t plen, dat_p;
 int8_t cmd;

 plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);

/*plen will ne unequal to zero if there is a valid packet (without crc error) */
 if(plen!=0){
         
   // arp is broadcast if unknown but a host may also verify the mac address by sending it to a unicast address.
   if(es.ES_eth_type_is_arp_and_my_ip(buf,plen)){
     es.ES_make_arp_answer_from_request(buf);
     return;
   }

   // check if ip packets are for us:
   if(es.ES_eth_type_is_ip_and_my_ip(buf,plen)==0){
     return;
   }
   
   if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V){
     es.ES_make_echo_reply_from_request(buf,plen);
     return;
   }
   
   // tcp port www start, compare only the lower byte
   if (buf[IP_PROTO_P]==IP_PROTO_TCP_V&&buf[TCP_DST_PORT_H_P]==0&&buf[TCP_DST_PORT_L_P]==mywwwport){
     if (buf[TCP_FLAGS_P] & TCP_FLAGS_SYN_V){
        es.ES_make_tcp_synack_from_syn(buf); // make_tcp_synack_from_syn does already send the syn,ack
        return;    
     }
     if (buf[TCP_FLAGS_P] & TCP_FLAGS_ACK_V){
       es.ES_init_len_info(buf); // init some data structures
       dat_p=es.ES_get_tcp_data_pointer();
       if (dat_p==0){ // we can possibly have no data, just ack:
         if (buf[TCP_FLAGS_P] & TCP_FLAGS_FIN_V){
           es.ES_make_tcp_ack_from_any(buf);
         }
         return;
       }
       if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0){
          // head, post and other methods for possible status codes see:
           // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
           plen=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1>200 OK</h1>"));
           goto SENDTCP;
       }
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: Btguillaume on Feb 16, 2013, 05:21 pm
Code: [Select]
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><br><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><br> ") );
        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';



}
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: alvydas001 on Feb 17, 2013, 07:04 pm
why dont use DallasTemperatureControl library?
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: Btguillaume on Feb 18, 2013, 12:12 am
Dallas's librairy?
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: alvydas001 on Feb 19, 2013, 06:50 pm

Dallas's librairy?

Yes,  why don't use Dallas's library?
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: Btguillaume on Feb 20, 2013, 02:17 am
what's that I juste done a quick google's search, but nothing interrested....

can you explain what's that?
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: Chagrin on Feb 20, 2013, 05:37 am
There's an Arduino library for "one wire" devices like the DS18B20.

http://playground.arduino.cc/Learning/OneWire
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: alvydas001 on Feb 20, 2013, 07:00 am

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
https://github.com/milesburton/Arduino-Temperature-Control-Library
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: teria on Apr 22, 2013, 04:05 pm
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?
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: Dmerlani on Apr 30, 2013, 10:31 pm
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!
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: Chagrin on May 01, 2013, 12:30 am
The client will make a request to your Arduino, typically with no authorization.

Code: [Select]
GET /foo HTTP/1.0
Host: foo.bar.com


Your arduino should respond with a request for authorization
Code: [Select]

403 Forbidden


The client will redo its request with credentials
Code: [Select]

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:

Code: [Select]
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.
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: Dmerlani on May 01, 2013, 09:24 pm
Hi, could you help me to integrate it in my code?
I am really a newbie...
Thanks!
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: sergiotux on Jul 24, 2013, 11:09 pm
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
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: elektrokan on Jan 04, 2014, 05:47 pm
  Nice project,  but I cant read temp value over the page  :~ I can read only 0.6 C and not changing. Please help.
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: Kryten on Jan 12, 2014, 09:33 am
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??
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: Aldeeb on Jan 13, 2014, 09:20 am
Reply to " elektrokan "
Your  problem is here
Code: [Select]
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.

Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: prozorianu on Jan 27, 2014, 03:37 am
Nice project !
How to edit the schetch to use ethernet shield based on wiznet5100 an DHT22 tmperature sensor  ?
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: daton on Feb 13, 2014, 07:39 am
Please could you tell me here insert links to the library used to 28j60. thank you
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: daton on Feb 24, 2014, 06:33 am
Please is this thread still alive? Could someone here insert links to the library used to 28J60? Thank you.
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: Chagrin on Feb 24, 2014, 07:01 am

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
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: chetan0412 on Apr 12, 2014, 12:55 pm
After uploading code i am not able to load page,

i have changed IP address as per my req.

need help
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: chiroskian on May 12, 2014, 10:24 pm
Hello i have a problem, in the web i only see 0°C and it never change.

I define the address of my DS1820 but it´s all the same.

Any idea about the problem? I´m using an Arduino Uno and Ethernet shield V1.1 .

Thanks!!
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: djkpap on Aug 25, 2014, 10:02 pm
hi guys i have arduino mega at mega 2560 and i cant compile this code.
i have this error
Arduino: 1.5.7 (Windows 8), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

web_control.ino:20:21: fatal error: OneWire.h: No such file or directory
compilation terminated.
i need this project
please help :smiley-red:
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: nmcfelix on Aug 27, 2014, 04:38 pm

hi guys i have arduino mega at mega 2560 and i cant compile this code.
i have this error
Arduino: 1.5.7 (Windows 8), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

web_control.ino:20:21: fatal error: OneWire.h: No such file or directory
compilation terminated.
i need this project
please help :smiley-red:


Do you have OneWire Library installed?
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: djkpap on Aug 30, 2014, 08:32 pm
yes library instaled but i have ethernet w5100!!
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: attiny85 on Sep 18, 2014, 04:14 pm
hi every one I'm new here. please I need this sketch for w5100 shield can some one edit it for me thanks :smiley-mr-green:
Title: Re: Arduino Webserver with Temperature Monitor / Control
Post by: koukou41 on Aug 17, 2015, 02:31 am
I want know whether Arduino Nano Clone is a USB Microcontroller or not? .Because I found a product in website named http://iteadstudio.com and the product name is Arduino Nano USB Microcontroller v3 (Clone version) .As you mentioned in your description the these words "Arduino" ,"Nano" and "Clone" words are containing in the product name Arduino Nano USB Microcontroller v3 (Clone version). If you mentioned the same product can you please tell me the prize you bought that part and from where you bought it. So I can compare it with the prizes in markets and buy the cheapest one

Dashquid (http://dashquid.com)
fatlossprofessional.co.uk (http://fatlossprofessional.co.uk)
fatlossprofessional (http://fatlossprofessional.co.uk/how-to-lose-weight-fast/)
mobilehelper (http://mobilehelper.co.uk)
securetrip (http://securetrip.co.uk)
whichpetcover (http://whichpetcover.com)
google (http://google.com)
abc (http://abc.com)
facebook (http://facebook.com)
craigslist (http://craigslist.com)
Useful sites listed above, I use most of them. EuropeGiant Classifieds (http://www.europegiant.com) is also a great one.