Here is the code so far.
/*
Fermenter Web Server
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Up to eight DS18B20's attached to Pin 9
Created June 26, 2013
by atoughram
*/
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
//Initialize the Onewire library with the DS10B20's on pin 9
//Install a 4.7K resistor between pin 9 and +5V
OneWire ds(9);
//Set up some variables
byte i, ii; //array pointers
byte dev[8] [8]; //device array
byte devpr; //Number of devices present
void setup() {
// Open serial communications
Serial.begin(9600);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
//Find all of the Onewire devices connected to pin 9
for (ii = 0; ii < 8; ii++) { //Up to eight devices
if (!ds.search(dev[ii])){ //if no devices found
Serial.println("No more devices found! ");
devpr = ii;
Serial.print("Number of devices found equal ");
Serial.println(devpr);
ds.reset_search();
delay(250);
return;
}
}
}
void loop() {
byte present = 0;
byte data [8] [12];
int16_t raw [8];
float celsius [8], fahrenheit [8];
//Print out the device serial numbers
for( ii = 0; ii < devpr; ii++) {
Serial.print("ROM =");
for( i = 0; i < 8; i++) {
Serial.write(' ');
Serial.print(dev[ii], HEX);
}
Serial.println("");
}
//Let get some data!
for( ii = 0; ii < devpr; ii++) { //Select which device
ds.reset();
ds.select(dev[ii]);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
present = ds.reset();
ds.select(dev[ii]);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[ii] = ds.read();
}
}
//Conversion time...
// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
for( ii = 0; ii < devpr; ii++) {
raw [ii]= (data[ii][1] << 8) | data[ii][0];
raw [ii]= (raw [ii] & 0xFFF0) + 12 - data[ii][6];
celsius [ii] = (float)raw [ii] / 16.0;
fahrenheit [ii] = celsius [ii] * 1.8 + 32.0;
Serial.print(" Temperature = ");
Serial.print(celsius [ii]);
Serial.print(" Celsius, ");
Serial.print(fahrenheit [ii]);
Serial.println(" Fahrenheit");
}
// listen for incoming clients on the Ethernet
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html><title>Garage Status</title>");
client.println("<body BGCOLOR='#ccffff'>");
client.println("<h1 style='text-align: center;'>Fermentation and Refrigerator Temps</h1>");
client.println("<table style='width: 100%' border='1'>");
client.println("<tbody>");
client.println("<tr>");
client.print("<td><font size=+10 color=#ff3300>Fermenter Cabinet <b>");
client.print(fahrenheit [0]);
client.println("f</b></font></td>");
client.print("<td><font size=+10 color=#3399cc>Refrigerator Temp <b>");
client.print(fahrenheit [1]);
client.println("f</b></font></td></tr>");
/* client.print("<tr><td><font size=+10 color=#3399cc>Sensor 3 <b>"); //Commented out - comment in whichever sensors your going to use.
client.print(fahrenheit [2]); //If celsius is preferred, change variable fahrenheit to celcius
client.println("f</b></font></td>"); //If celsius is preferred, change f at beginning of line to c
client.print("<td><font size=+10 color=#3399cc>Sensor 4 <b>");
client.print(fahrenheit [3]);
client.println("f</b></font></td></tr>");
client.print("<tr><td><font size=+10 color=#3399cc>Sensor 5 <b>");
client.print(fahrenheit [4]);
client.println("f</b></font></td>");
client.print("<td><font size=+10 color=#3399cc>Sensor 6 <b>");
client.print(fahrenheit [5]);
client.println("f</b></font></td></tr>");
client.print("<tr><td><font size=+10 color=#3399cc>Sensor 7 <b>");
client.print(fahrenheit [6]);
client.println("f</b></font></td>");
client.print("<td><font size=+10 color=#3399cc>Sensor 8 <b>");
client.print(fahrenheit [7]);
client.println("f</b></font></td></tr>"); */
client.println("</tbody>");
client.println("</table>");
client.println("</body>");
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}